Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there some sort of canonical edn response we can use for ring?

Tags:

clojure

ring

edn

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?

like image 303
zcaudate Avatar asked Jun 12 '13 20:06

zcaudate


1 Answers

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.

like image 130
ToBeReplaced Avatar answered Oct 23 '22 23:10

ToBeReplaced