pedestal

subsaharancoder 2020-08-11T03:40:27.329600Z

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

subsaharancoder 2020-08-11T04:32:07.329800Z

figured this out

👍 2
dangercoder 2020-08-11T17:31:46.338400Z

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)

2020-08-11T17:36:05.339600Z

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

👍 1
dangercoder 2020-08-11T17:39:26.341700Z

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

2020-08-11T17:41:10.342700Z

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

isak 2020-08-11T17:43:06.343400Z

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

dangercoder 2020-08-11T18:10:18.346800Z

indeed isak, one always has to think about roundtrips 🙂