When handling a http request inside a ring server, the body of the request-data is stored in the request-hashmap in the key :body
. For instance as followed:
You can use ring.util.request/body-string to get the request body as a String.
(body-string request)
You need to remember that InputStream
can be read only once so you might prefer replace the original :body
with the read String
instead so you can later access it again:
(defn wrap-body-string [handler]
(fn [request]
(let [body-str (ring.util.request/body-string request)]
(handler (assoc request :body (java.io.StringReader. body-str))))))
And add your middleware to wrap your handler:
(def app
(wrap-body-string handler))