Fork me on GitHub
#pedestal
<
2019-07-17
>
Daouda10:07:26

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]}))

Daouda10:07:51

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))

Daouda11:07:18

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 ?

ddeaguiar13:07:18

@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)}))

Daouda13:07:29

oh, how did you noticed that my project was based on pedestal service template? curiosity 😄 Can I use nested level route with this template?

ddeaguiar13:07:09

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).

ddeaguiar13:07:41

you’d have to create a separate route vector for, for example, /about/foobar

Braden Shepherdson14:07:42

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.