I've been reading the edn spec and want to integrate it into my application. However, I don't know how to transfer edn requests between clojure and client. Do we put a content-type application/edn in the response header and just send the prn output string?
Although it has not yet been accepted by IANA (June 14, 2013), the correct content-type is application/edn
. To provide a valid string output of your clojure object, use (pr-str obj)
. For a web service, the method of encoding and decoding depends on your web framework and your needs.
Pedestal supports parsing of edn into an :edn-params
key on its request map through the use of its body-params
interceptor. Sending clojure objects as edn is handled automatically if your response bodies are not strings. For content-negotiation, see pedestal-content-negotiation.
For ring middleware, ring-edn parses edn into an :edn-params
key, but does not do any outbound modification. ring-middleware-format provides parsing of a handful of different formats into the :body-params
key, and has a collection of middlewares that can be helpful for responses as well. There are a handful of other ring middleware projects like this out there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With