beginners 2025-07-08

I am trying to run a Ring Jetty server and, when I get a POST request, the :body is of type org.eclipse.jetty.ee9.nested.HttpInput. What is this? How do I just read in EDN for the post?

Davi Nascimento de Azevedo DNA 2025-07-10T20:59:31.620089Z

Hi! The arguments probably are on :body-params if it is a json or something like it.

Davi Nascimento de Azevedo DNA 2025-07-10T21:04:07.117549Z

If you need the raw request body, you may need a middleware before format-middleware that extracts the raw body from :body and then replaces it's input stream by a new with the same content. I've made it when i had the same problem yesterday:

(defn wrap-raw-body [handler]
  (fn [request]
    (handler (let [raw-body (-> request :body slurp)]
               (assoc request
                      :body (java.io.ByteArrayInputStream. (.getBytes raw-body))
                      :raw-body raw-body)))))

I'm not familiar with reitit, but: 1. Can you provide a minimal, self-contained bit of code that exposes the issue you're getting? 2. The wrap-jsonbody` middleware will only try to parse content as JSON if the request has a Content-Type: application/json header, and will only succeed if the provided text is actually JSON.

It’s an input steam. Here’s an example of how a common middleware turns this into parsed JSON: https://github.com/ring-clojure/ring-json/blob/master/src/ring/middleware/json.clj#L16

Hmm, I had tried that but it doesn't seem to work with Reitit.

(def routes
  (->
   (reitit.ring/ring-handler
    (reitit.ring/router
     [["/" {:get home-page}]
      ["/authenticate/login" {:post auth/login-route}]])
    (ring/create-default-handler)
    {:middleware [reload/wrap-reload wrap-json-body]})))

I also tried with Muutanja, it seems like I have something misoconfigured

(def routes
  (->
   (reitit.ring/ring-handler
    (reitit.ring/router
     [["/" {:get home-page}]
      ["/authenticate/login" {:post auth/login-route
                              :data {:middleware [wrap-json-body]}}]]
     {:data {:middleware [format-middleware]
             :muuntaja muuntaja/instance}})
    (ring/create-default-handler)
    {:middleware [reload/wrap-reload]})))