Fork me on GitHub
#pedestal
<
2019-01-29
>
donaldball19:01:39

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?

donaldball19:01:16

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

ddeaguiar19:01:29

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

ddeaguiar19:01:53

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

ddeaguiar19:01:12

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

donaldball19:01:25

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