Fork me on GitHub
#pedestal
<
2022-03-27
>
popeye15:03:53

I am using pedatsal web framework

(defn study-fn [ctx]
 // transformation on ctx
)   

(def interceptor-1
  {:name :studies
   :enter study-fn})

["/rest/get-studis" :get [interceptor-1] :route-name :studies]
Is there a way where we can pass an extra function in the routs? like below
["/rest/get-studis" :get [interceptor-1  (fn [] {:message "message"} )] :route-name :studies]
so that study_fn can be something like below
(defn study-fn [ctx parameter]

 // transformation on ctx

)

pithyless16:03:50

@U01J3DB39R6 This is not specific to pedestal, but what you usually want to do in cases like this is create a closure that returns parameterized functions (sometimes referred to as "close over a function") - and not to be confused with "Clojure". This way you can customize the function, without needing to change the underlying API.

(defn make-study-fn [opts]
  (fn [ctx] "Here you have access to both ctx and opts"))


(defn interceptor-1 [opts]
 {:name :studies
  :enter (make-study-fn opts)})


["/rest/get-studies" :get [(interceptor-1 {:message "message"})] ,,,]

popeye18:03:12

thanks for the response @U05476190, Will try this