pedestal

donaldball 2019-01-29T19:17:39.021300Z

When using the table routing syntax, what is the suggested way of applying a seq of interceptors to e.g. all routes under a given path?

donaldball 2019-01-29T19:20:16.022100Z

I had thought that registering the interceptors as metadata in a wrapping vector would do it but that seems not to be true

2019-01-29T19:27:29.024Z

Hi @donaldball! You can create a var bound to the vector of common interceptors and conj your handler into it. With the table routing syntax, you’ll need to do this for each route

2019-01-29T19:27:53.024400Z

A project created using the service template will have an example of this

2019-01-29T19:28:12.024600Z

(def common-interceptors [(body-params/body-params) http/html-body])

;; Tabular routes
(def routes #{["/" :get (conj common-interceptors `home-page)]
              ["/about" :get (conj common-interceptors `about-page)]})

donaldball 2019-01-29T19:30:25.025500Z

Yeah, that’s what I’m doing now, but it’s ergonomically less appealing than earlier syntaxes allowed. Then again, that’s what fns are for. 🙂