Fork me on GitHub
#clojurescript
<
2023-08-20
>
Dallas Surewood08:08:53

Is there a way to accept EDN from CLJS when making a request to the backend? I have some values that are keywords, but since these get lost on request, it sounds like I shouldn't do this if I except the frontend will consume it

thheller08:08:54

is your backend sending edn? what do you use to make the request?

thheller08:08:18

yes, it is easy to exchange actual EDN

Dallas Surewood08:08:32

I'll try to find where this is set on my server

Dallas Surewood08:08:02

Also I'm using cljs-http to make the requests

thheller08:08:11

I have never used that library, so my help with that is limited. but I'd assume it supports EDN just fine if your server actually sends it

thheller08:08:25

if the server sends JSON that is a problem

Dallas Surewood08:08:51

cljs-http certainly sends EDN fine, have not confirmed if there's an option somewhere to opt-in to receiving it

thheller08:08:24

just look in the browser network devtools panel to see what you actually get

thheller08:08:43

the request will have a content-type header and you should be able to look at the response itself

Dallas Surewood08:08:18

Oh yes, that is JSON. I figured if a CLJS library only accepted JSON then that's all I would get back if the server could do both

Dallas Surewood08:08:22

So I gotta read ring documentation and figure out what option I need to pass to send back EDN

Dallas Surewood08:08:12

Seems the server uses muuntaja and that expects the requester to provide a special header telling it what format to respond in. Trying to figure out where to put that

thheller08:08:24

thats usually "negotiated" by the client sending an Accept header, don't know if cljs-http does that on its own though

Dallas Surewood08:08:24

No, but I just figured that out. Added the header and it changed the response. Thank you!

Dallas Surewood09:08:22

Is there a reason people prefer transit+json over edn?

Stef Coetzee09:08:13

From what I understand, Transit is more performant. Good background discussion: https://open.spotify.com/episode/2DDbXnVVxkr96ADPvNH7fQ Separately: https://groups.google.com/g/clojure/c/9ESqyT6G5nU/m/2Ne9X6JBUh8J "edn is the best choice for human-readable data." "fressian is the highest performance option" "transit is a pragmatic midpoint between these two"

👍 2
hifumi12310:08:59

transit+json is more performant in the browser since JSON parsing gets tons of optimization that EDN parsing simply cant get

hifumi12310:08:49

though IMO, if you want the most convenience for the least effort, EDN is just fine… transit+json is good when you want convenience in the CLJS side w/o sacrificing as much performance as sticking with pure EDN