Hey folks, I am trying to use expand-route
with no success. It`s my first time to use pedestal and I am a bit lost.
(def routes
(route/expand-routes
#{["/" :get [common-interceptors] `home-page]
["/about" :get [common-interceptors] `about-page]
["/user" :post [common-interceptors] `create-user]}))
1. Caused by java.lang.AssertionError
Assert failed: Route name or handler appears more than once in the
route spec: [[#Interceptor{:name
:io.pedestal.http.body-params/body-params} #Interceptor{:name
:io.pedestal.http/html-body} #Interceptor{:name }]] (nil?
(seen-route-names rname))
the error seems obvious but i don`t know how to get right of it, anything I tried so far, I get other kind of error. Any help about the right way to use expand-routes
?
@quieterkali, your service is based on the pedestal-service template then io.pedestal.http/default-interceptors
is being called then you don’t need route/expand-routes
. In terms of your routes, it looks you are using the table route syntax but it’s not complete correct. It should look something like this:
(def routes
(route/expand-routes
#{["/" :get (conj common-interceptors `home-page)]
["/about" :get (conj common-interceptors `about-page)]
["/user" :post (conj common-interceptors `create-user)}))
oh, how did you noticed that my project was based on pedestal service template? curiosity 😄 Can I use nested level route with this template?
Lucky guess 🙂. Table route syntax does not support nested routes. However, I find it to be the preferred route syntax because it’s easier to reason about (for me anyways).
you’d have to create a separate route vector for, for example, /about/foobar
curious, I find the hierarchy more difficult to follow once it grows beyond a handful of layers or a dozen routes total. I like being able to see all the routes laid out in full.