Fork me on GitHub

Hi, how can I do the equivalent of curl -X GET -H "Content-Type: application/json" -d '{"bar": "baz"}' (a GET request with json data attached to it with cljs-http?


I tried that though


(defn search
    (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 etc


in 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-http


thank you for the help


It's something I've discovered first when using elasticsearch because they use that strategy everywhere for their search queries


staring at a GET request with a body


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:

Nazral04:07:28 < well I guess it's simply not possible in javascript, so I doubt it will be possible in clojurescript? :thinking_face:


oh well, thanks again for the help anyway 😛


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)

👍 3

I’m using the magic link api’s and here’s an example of how it’s used. (OAuthExtension is the same as MagicOAuthExtension): 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
                             {: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:


I have an input created by reagent, and a separated function that affects its value through (set! (.-value (gdom/getElement "inputid")) someval) and I get the correct (.-value (gdom/getElement "inputid"))` after the set, however I don't see it in the input box, why is that?


Is it because of the lack of onChange handler?


(I solved the issue but I am still not sure what it happened in the first place)


Are you using a :value key in your component?


No I wasn't


@denis.baudinot PRs welcome - should probably include a link to Figwheel too

👍 6