scittle

m3tti 2024-06-24T11:13:13.757389Z

hey guys how do i use js/fetch in scittle πŸ˜• my post request doesn't work doing it like that (js/fetch some-url {:method "POST" :body (js/JSON.stringify {:bla "bla"})})

2024-06-29T07:53:51.388149Z

Sorry I meant js/fetch function

borkdude 2024-06-29T07:55:13.065149Z

What about the js/fetch function?

2024-06-29T09:58:43.337489Z

I used to run the function like this (js/fetch some-url {:method "POST" :body (prn {:bla "bla"})}) assuming that prn convert the map to json.stringify based on the readme in github. However, the body on the server is nil. I just tried what @mathaeus.peter.sander did initially and worked.

2024-06-29T09:59:52.126689Z

pr-str works as well

borkdude 2024-06-29T10:04:47.096269Z

Prn is a side effecting function which prints

borkdude 2024-06-29T10:04:55.431039Z

And that function returns nil

borkdude 2024-06-29T10:05:44.858869Z

It’s best to manually call JSOn stringify in squint rather than using pr-str

πŸ‘ 1
borkdude 2024-06-24T11:18:41.031709Z

Use #js {:body ...} since js/fetch is a JavaScript thing, not a CLJS library

borkdude 2024-06-24T11:19:04.281889Z

or use clj->js

m3tti 2024-06-24T11:19:22.428739Z

aaaaaah i see

m3tti 2024-06-24T11:19:34.624129Z

i guess i should more ofter refer to squint πŸ˜„

m3tti 2024-06-24T11:19:42.056199Z

when using scittle

m3tti 2024-06-24T11:29:34.273659Z

hrm now the issue is that my send data is edn πŸ˜„

m3tti 2024-06-24T11:30:15.780869Z

(js/fetch api-url #js {:method "POST" :body {:dataType "json" :q (:search-term @state)}})
btw can scittle use the js-await ?

borkdude 2024-06-24T11:30:49.995019Z

you need to also write :body #js {....} , #js isn't recursive

borkdude 2024-06-24T11:31:01.836529Z

or use clj->js which is recursive

borkdude 2024-06-24T11:31:20.162269Z

scittle doesn't support js-await, but it comes with promesa which helps dealing with promises

2024-06-28T20:54:19.425609Z

Does the same applies for squint?

borkdude 2024-06-28T21:10:52.334899Z

please specify "the same"

borkdude 2024-06-28T21:14:38.221609Z

in squint you don't have to write #js because that is the only thing that exists, everything is JS data structures also, squint supports js-await