This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-02
Channels
- # announcements (7)
- # atom-editor (3)
- # babashka (8)
- # beginners (38)
- # biff (5)
- # calva (17)
- # cider (26)
- # clj-kondo (6)
- # clojure (49)
- # clojure-europe (47)
- # clojure-norway (19)
- # clojure-sweden (2)
- # clojure-uk (1)
- # clojurescript (22)
- # cursive (20)
- # datahike (1)
- # datomic (6)
- # etaoin (2)
- # honeysql (2)
- # hyperfiddle (36)
- # jobs-discuss (19)
- # leiningen (15)
- # malli (5)
- # off-topic (8)
- # overtone (1)
- # pathom (15)
- # pedestal (8)
- # polylith (4)
- # releases (1)
- # ring (5)
- # schema (10)
- # shadow-cljs (17)
- # timbre (3)
- # xtdb (17)
I have this code from https://www.youtube.com/@andrey.fadeev tutorial:
(def routes
(route/expand-routes
#{["/greet" :get respond-hello :route-name :greet]
["/todo/:todo-id" :get get-todo-handler :route-name :get-todo]}))
where respond-hello
is a function and get-todo-handler
is an interceptor. Does expand-routes
accept both function and interceptor?http://pedestal.io/pedestal/0.7-pre/guides/defining-routes.html says "The simplest route has just a URL, an HTTP verb, and a handler:
["/users" :get view-users]
"If the value after the method (:get) is a vector, then it should be a vector of interceptors. Technically, things that satisfy the IntoInterceptor protocol.
(defprotocol IntoInterceptor
(-interceptor [t] "Given a value, produce an Interceptor Record."))
(declare interceptor)
(extend-protocol IntoInterceptor
IPersistentMap
(-interceptor [t] (map->Interceptor t))
; This is the `handler` case
Fn
(-interceptor [t]
(let [int-meta (meta t)]
;; To some degree, support backwards compatibility
(if (or (:interceptor int-meta)
(:interceptorfn int-meta))
(interceptor (t))
(interceptor {:enter (fn [context]
(assoc context :response (t (:request context))))}))))
IPersistentList
(-interceptor [t] (interceptor (eval t)))
Cons
(-interceptor [t] (interceptor (eval t)))
Symbol
(-interceptor [t] (interceptor (resolve t)))
Var
(-interceptor [t] (interceptor (deref t)))
Interceptor
(-interceptor [t] t))
Functions are normally handlers, though with (not documented but in this code!) metadata, they can be functions that returns interceptors. Symbols are resolved, and Vars are de-refed. This is all still pretty static though, as the resolving/deref-ing/invoking all happens at route expansion time, thus the need for all the tricks here: http://pedestal.io/pedestal/0.7-pre/guides/live-repl.html
