Fork me on GitHub
#clojurescript
<
2021-07-08
>
Nazral04:07:25

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?

Nazral04:07:31

I tried that though

Nazral04:07:14

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

Nazral04:07:19

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

Nazral04:07:32

thank you for the help

Nazral04:07:49

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

deleted04:07:56

staring at a GET request with a body

quoll04:07:32

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

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:

Nazral04:07:37

oh well, thanks again for the help anyway 😛

Nazral05:07:27

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
zendevil.eth06:07:20

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.

dgb2307:07:53

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

Nazral09:07:12

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?

Nazral09:07:38

Is it because of the lack of onChange handler?

Nazral09:07:56

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

Lu11:07:00

Are you using a :value key in your component?

Nazral11:07:15

No I wasn't

dnolen15:07:07

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

👍 6