This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-27
Channels
- # announcements (8)
- # babashka (7)
- # beginners (24)
- # biff (5)
- # calva (17)
- # cider (1)
- # clj-kondo (4)
- # clojure (61)
- # clojure-europe (5)
- # clojure-norway (19)
- # clojurescript (17)
- # conjure (1)
- # core-typed (14)
- # cursive (9)
- # datomic (7)
- # events (2)
- # figwheel (2)
- # helix (1)
- # honeysql (4)
- # jobs (3)
- # lsp (3)
- # malli (2)
- # nrepl (13)
- # off-topic (9)
- # pathom (6)
- # pedestal (3)
- # polylith (3)
- # portal (7)
- # reagent (4)
- # reitit (2)
- # shadow-cljs (49)
- # tools-deps (8)
- # vim (3)
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
)
@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"})] ,,,]
thanks for the response @U05476190, Will try this