Fork me on GitHub
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 ""
     {"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?


@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


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


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


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 👍.


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.


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)


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?


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

🙌 4

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


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


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


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:


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


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


at least as beginner


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

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


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


Ohh hadnt seen that yet! Thanks for pointing that out


Cant move the thread can I?:rolling_on_the_floor_laughing:


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

clojure-spin 2

Scittle is absolutely cool!

clojure-spin 2