This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-08
Channels
- # announcements (22)
- # aws (4)
- # babashka (25)
- # beginners (78)
- # calva (9)
- # cider (22)
- # cljdoc (2)
- # cljsrn (2)
- # clojure (27)
- # clojure-australia (7)
- # clojure-europe (22)
- # clojure-nl (15)
- # clojure-uk (26)
- # clojurescript (20)
- # datahike (3)
- # datomic (15)
- # events (1)
- # helix (5)
- # honeysql (4)
- # kaocha (1)
- # malli (1)
- # meander (1)
- # off-topic (84)
- # pathom (14)
- # re-frame (3)
- # reagent (28)
- # reitit (6)
- # sci (1)
- # shadow-cljs (78)
- # tools-deps (30)
Hi, how can I do the equivalent of curl -X GET
(a GET
request with json data attached to it with cljs-http
?
(defn search
[]
(go
(let [resp
(<! (http/get
(str srv-addr "/ops")
{:with-credentials? false
:headers {"Content-type" "application/json"}
:query-params {:body (.stringify js/JSON (clj->js {:calls false}))}}))
{:keys [quotes options catalysts]} (-> resp :body read-string)]
(println (count options)))))
the line query-params
I have tried a variety of things nothing works (note that the curl call perfectly works)
I have tried :json-params
with the edn map directly, I've tried query-params as you can see etcin python I could simply do
r = requests.get("", data = '{"bar": "baz"}', headers= {'Content-Type': 'application/json'})
and it would just work, but I cannot find the equivalent of this data
field in cljs-httpIt's something I've discovered first when using elasticsearch because they use that strategy everywhere for their search queries
The HTTP/1.1 RFC is frustratingly vague on GET with a body. Requests like this are not explicitly disallowed, but they are also not given any semantics. Meanwhile requests which do not define semantics for a body SHOULD have that body dropped by a server. So you can’t rely on it working, unless you control both the client and server. But it’s legal, and I’ve seen it used in APIs :woman-shrugging:
https://stackoverflow.com/questions/54810942/send-a-get-request-with-a-body-in-javascript-xmlhttprequest < well I guess it's simply not possible in javascript, so I doubt it will be possible in clojurescript? :thinking_face:
it doesn't work either, but it's ok I can just add a POST on the backend side (luckily for this case I do control the backend)
I’m using the magic link api’s and here’s an example of how it’s used. (OAuthExtension is the same as MagicOAuthExtension): https://codesandbox.io/s/2d9jo I have the following code:
(defn login []
(let [magic (Magic. "pk_live_123456"
(clj->js {:extensions [(OAuthExtension.)]}))
_ (go (js/console.log "is logged in " (<p! (.. magic -user (isLoggedIn)))))
]
[:button {:on-click #(.. magic -oauth
(loginWithRedirect
(clj->js
{:provider "facebook"
:redirectURI (.. js/window -location -origin)})))} "Facebook"]))
But even after the redirect from clicking the magic button, the go block still prints false for loggedIn(). Any ideas why this would be? It’s expected to print true after the redirect after the login flow of facebook happens.Is it just me or could the official website be a bit improved? For example the tools section is quite bare bones and doesn’t cover some of the popular tools like shadowcljs: https://clojurescript.org/tools/tools