Fork me on GitHub
#babashka
<
2023-02-12
>
Matthew Twomey08:02:37

I am trying to do the equivalent of this curl using the new babashka/http-client:

curl --location --request PATCH '' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer blablabla \
--data-raw '{
	"name": "name1",
	"template": false,
	"certificate": "656e239e-2442-4261-ae29-9e2442f261b8",
	"enabled": true,
	"identities": ["3fa941ee-9491-4373-a941-ee9491b3713e"]
}'
However when I try to do this with:
(http/patch ""
  {:headers
     {"authorization" "Bearer blablabla"}
   :body "{\"name\": \"name1\",\"template\": false,\"certificate\": \"656e239e-2442-4261-ae29-9e2442f261b8\",\"enabled\": true,\"identities\": [\"3fa941ee-9491-4373-a941-ee9491b3713e\"]}"})
I get an HTTP 415 Unsupported Media Type. I think it’s related to the JSON I’m trying to pass. But I can’t seem to get it into the “raw” sort of format I need similar to the curl. Anyone have any clues?

borkdude08:02:33

@U0250GGJGAE I think you might need to set the content type explicitly to application/x-www-form-urlencoded

Matthew Twomey08:02:47

The API wont handle urlencoded posts / patches, it need application/json - but let me explicitly set that and see

borkdude08:02:59

Then you'll need to set the content type to json

borkdude08:02:43

{:headers {:content-type "application/json"}}

borkdude08:02:27

sorry, I missed the content type in your curl request, curl by default sends the content type I wrote earlier.

Matthew Twomey08:02:59

Ok - yeah, I think that’s gotten me past this hurdle. Checking further, but I think that did it. Thank you sir.

👍 2
Matthew Twomey09:02:11

Confirmed fully. All good now 👍.

Thierry14:02:27

I was wondering, I am fooling around with scittle inside a ring, sibiro, hiccup made website - which works great btw. Would it be somehow possible to trigger a Clojure function in the surrounding code from inside scittle code? I copied the default scittle examples and they work perfectly. https://gist.github.com/LouDnl/82b4020555afaf322a3381525451052d

Benjamin16:02:14

do you mean in the sense of sharing code between server and browser or do you mean in the sense of browser making a web request (like in example)

Thierry16:02:23

In any sense for that matter. Doing requests server side back and forth to transit requests would be the simplest I guess? I am just messing around with scittle (which is really cool btw), using it inline in a Clojure project that uses hiccup. See snippet above. Would there - without using server side requests - be any way to call a Clojure function that is outside the [:script] tag? Probably not I'm guessing?

Thierry16:02:58

For this test I want to save myself the hassle of adding Clojurescript to the project and Scittle is superb for that

🙌 4
Benjamin16:02:22

you could move the code you want to share into a cljs file, and use script src=/fiile.cljs with "application/x-scittle" type and it gets loaded

Thierry16:02:22

Thats one thing then, but from that cljs file it would be possible to trigger a Clojure function without a request?

Benjamin16:02:47

You'll need a request at some point if the browser should trigger something on the server. Probably ajax + ring handlers is what you want

Thierry16:02:40

Good point indeed. For other projects I use jQuery to reload a hiccup div into itself and it automatically reloads the clojure code :melting_face:

Thierry16:02:08

First time venturing into Scittle as it seems much easier to start with then adding cljs to a clj project

Benjamin16:02:41

yea I had the same experience it immediately works and Clojurescript is sort of heavy to use

Benjamin16:02:55

at least as beginner

Thierry16:02:22

Indeed, it had me add more dependencies, needs to be compiled to use. Very confusing if you have not done that before but do know your way around clj

yes 2
borkdude17:02:32

@U02CX2V8PJN There's also a #C034FQN490E channel :-)

borkdude17:02:11

Can you move the big chunk of code to a Github gist or attachment or so? It's good etiquette not to flood the channel with big chunks of text

Thierry17:02:14

Ohh hadnt seen that yet! Thanks for pointing that out

Thierry17:02:08

Cant move the thread can I?:rolling_on_the_floor_laughing:

borkdude17:02:49

No worries, next time :) It's good to remind babashka users of scittle now and then :)

clojure-spin 2
Thierry17:02:28

Scittle is absolutely cool!

clojure-spin 2