How do I send and receive edn using a POST handler in Clojure?

I am sending a map via a POST using cljs-http and I want to receive it with a Compojure POST handler and store it in a database. I'm totally confused as what I am supposed to do with the map in transit... there are a lot of options... pr-str, prn, read-string and on and on. On the sending side, it seems cljs-http might coerce my map into edn on it's own. I have no way of knowing without a working Compojure handler. However, the :data value on the request is an object, not a string. A working example of a cljs-http POST and a Compojure POST handler that allows me to work with the original map sent by the client would be awesome. I don't know the purpose of :edn-params in my

(http/post "/test" (:edn-params (prn-str {:hey "there"})))

or if I should be using something else. I am used to JSON and am wondering if I should just be converting the data to JSON and back out on the receiving side. I'm unsure of the advantages of using edn.

On the receiving side I have:

(defroutes handler
  (GET "/about" [] "<h1>Hello World</h1>")
  (POST "/test" req (prn (read (:body req))))
  (route/not-found "<h1>Page not found</h1>"))

I know this likely wrong... but I thought I'd share where I am at.



Read more here: https://stackoverflow.com/questions/67378920/how-do-i-send-and-receive-edn-using-a-post-handler-in-clojure

Content Attribution

This content was originally published by THX1137 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: