This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-27
Channels
- # announcements (10)
- # aws (11)
- # beginners (158)
- # calva (8)
- # cider (14)
- # clj-kondo (1)
- # cljsrn (1)
- # clojure (83)
- # clojure-europe (5)
- # clojure-italy (25)
- # clojure-nl (3)
- # clojure-spec (12)
- # clojure-uk (20)
- # clojurescript (72)
- # community-development (18)
- # core-async (4)
- # core-logic (19)
- # cursive (11)
- # datomic (21)
- # duct (6)
- # events (1)
- # figwheel-main (3)
- # fulcro (15)
- # ghostwheel (1)
- # jobs (1)
- # leiningen (16)
- # off-topic (45)
- # onyx (3)
- # pathom (7)
- # perun (1)
- # ring (3)
- # shadow-cljs (48)
- # spacemacs (10)
- # specter (1)
- # sql (24)
- # tools-deps (7)
- # vscode (7)
- # xtdb (14)
Morning 🙂 I read somewhere recently (it might have been an old post as I can't find it now) that Ring only supported synchronous handlers, but I can see examples in the docs showing the use of middleware to add support for asynchronous handlers. Something along the lines of:
(defn content-type-response [response content-type]
(assoc-in response [:headers "Content-Type"] content-type))
(defn wrap-content-type [handler content-type]
(fn
([request]
(-> (handler request) (content-type-response content-type)))
([request respond raise]
(handler request #(respond (content-type-response % content-type)) raise))))
Is this example the currently supported/preferred method for adding asynchronous handler support within ring projects or is there some other method that is/will be supported with ring core?Yes, that example is correct. Async support in Ring is handled by the three-arity handler function. It’s also a good idea to split the middleware into -request
and -response
functions so that people can manually create their own async interceptors, etc.
Perfect, thanks @U0BKWMG5B 👍