Fork me on GitHub
#pedestal
<
2017-10-04
>
zallin13:10:20

hey everyone. does pedestal out of the box support interceptors scoped by request method and not by verb map ? cant find anything in docs on that regard ..

zallin13:10:30

["/:id" ^{:interceptors [load-order-from-db]} {:get view-order :put update-order}]

zallin13:10:02

here interceptors will be invoked for both get and put methods

zallin13:10:32

what if i want to create interceptor that only works for put method for instance ?

mtnygard13:10:06

@zallin You can definitely do that.

mtnygard13:10:09

It would look like this:

mtnygard13:10:28

["/:id" ^{:interceptors [load-order-from-db]}
           {:get view-order
            :put [put-only-intc update-order]}]

mtnygard13:10:43

It’s much easier to express in table routing syntax.

zallin13:10:17

ok thanks ! will try that

mtnygard13:10:18

["/:id" :get [load-order-from-db view-order]]
["/:id" :put [load-order-from-db put-only-intc update-order]]

zallin14:10:04

and also can i provide handlers as vars so they are resolved dynamically and i need not to restart pedestal each time i change logic inside of a handler ?

mtnygard14:10:49

The usual way to do that is by providing the route table as a var, not just the handlers. One sec & I can find a link.

mtnygard14:10:26

That’s from the leiningen template for the server.

mtnygard14:10:55

Line 21 shows how the :io.pedestal.http/routes key can have a function instead of just a value.

zallin14:10:07

ok I see thanks for your help !