This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-24
Channels
- # ai (41)
- # announcements (4)
- # babashka (14)
- # beginners (24)
- # calva (7)
- # clj-kondo (36)
- # cljsrn (4)
- # clojure (68)
- # clojure-austin (2)
- # clojure-europe (39)
- # clojure-nl (2)
- # clojure-norway (37)
- # clojure-uk (2)
- # clojurescript (7)
- # clr (8)
- # community-development (16)
- # core-async (7)
- # datalevin (67)
- # fulcro (11)
- # helix (1)
- # honeysql (2)
- # london-clojurians (2)
- # off-topic (60)
- # pedestal (3)
- # portal (2)
- # practicalli (1)
- # re-frame (7)
- # reitit (49)
- # releases (3)
- # shadow-cljs (2)
- # xtdb (16)
Did you ever use http_fx and then wanted to access the response headers? Because I do right now.
There most likely is a way to access them by specifying some custom response format. The implementation of the underlying cljs-ajax
is hard to follow due to the heavy reliance on protocols and
so can't tell for certain how to do it without spending too much time on it.
However, there's a different library that relies on js/fetch
that also has that functionality built-in: https://github.com/superstructor/re-frame-fetch-fx#success-handling
With cljs-ajax you can use a response-format
like
{:content-type "something"
:description "raw"
:read identity}
:read
is a function that that manipulates the original response object where you can get the headers. If I recall, you can use these protocol methods to work with the response object https://github.com/JulianBirch/cljs-ajax/blob/master/src/ajax/protocols.cljc#L15-L28And I agree with ☝️ that this was not trivial to figure out from the docs or from the source code.
Hey @U02CV2P4J6S!
Did you figure this out?
I did this a few months ago by adding the following to :http-xhrio
effect
:response-format
{:read (fn [xhrio]
{:status (ajax.protocols/-status xhrio),
:headers (ajax.protocols/-get-all-headers
xhrio)})},
So, in the on-success
or on-failure
handler, I desctured the response as follows:
{{:keys [status headers]} :response}