Fork me on GitHub
#pedestal
<
2020-08-11
>
subsaharancoder03:08:27

What's the recommended way of setting up a route with an interceptor for body-params? I have this:

["/api/users"
       :post [(body-params/body-params)]
       ;user-handler
       :route-name :user-handler
       ]
with my handler:
(defn user-handler
  [{:keys [headers params json-params path-params] :as request}]
  {:status 200 :body "/api/users"})
but doesn't seem to work

subsaharancoder04:08:07

figured this out

dangercoder17:08:46

When you compose interceptors, whats the preferred pedestal way? Many interceptors or few interceptors? Example: 1. "light weight interceptors"

(conj common-interceptors
      error-handler
      coerce-create-transaction-request
      with-jdbc-transaction-interceptor!
      get-current-user-interceptor!
      get-current-system-status-interceptor!
      validate-user-balance-interceptor
      save-transaction-interceptor!
      notify-booking-system-interceptor!)
2. "heavy-weight-interceptors"
(conj common-interceptors
      error-handler
      coerce-create-transaction-request
      handle-create-transaction-interceptor)

ddeaguiar17:08:05

I tend to prefer small interceptors where each focuses on a single responsibility but I suppose it depends on context

👍 3
dangercoder17:08:26

To me, having small interceptors which focus on a single responsibility makes things more explicit

ddeaguiar17:08:10

plus they are easier to reason about, test, etc…

isak17:08:06

A downside could be performance. E.g., 10 round-trips to the database, instead of just 1

dangercoder18:08:18

indeed isak, one always has to think about roundtrips 🙂