pedestal

Daouda 2019-07-17T10:51:26.067Z

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

Daouda 2019-07-17T10:59:51.067600Z

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

Daouda 2019-07-17T11:02:18.069500Z

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 ?

2019-07-17T13:16:18.073200Z

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

Daouda 2019-07-17T13:19:29.073300Z

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

2019-07-17T13:55:09.073600Z

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

2019-07-17T13:55:41.073800Z

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

2019-07-17T14:12:42.074Z

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.