metosin / compojure-api

Sweet web apis with Compojure & Swagger
http://metosin.github.io/compojure-api/doc/
Eclipse Public License 1.0
1.11k stars 149 forks source link

Can't access whole form parameter list during handler execution #442

Open Invertisment opened 4 years ago

Invertisment commented 4 years ago

Library Version(s)

[org.clojure/clojure "1.10.1"]
[metosin/compojure-api "1.1.13"]
[ring/ring-core "1.8.0"]
[metosin/muuntaja "0.6.6"]
[metosin/ring-http-response "0.9.1"]

Problem

I want to get all form/body parameters (or body string) in my request. I've tested out many ways and I can't find any way to do it. I added many details in this SO question: https://stackoverflow.com/questions/61206840/how-do-i-obtain-all-of-plain-post-form-parameters-in-compojure-api-sweet

I've registered an answer there first because I thought it's a problem of not being familiar with ring and compojure-api. But there is not so much people traffic. If you're interested in more details then read the SO question too.

Code (SO version contains longer one):

(POST "/api/:variable" req
       (println
                (:form-params req) ;; {}
                (:body-params req) ;; {}
                (:params req)      ;; {:variable asd}
                (:body req))       ;; #object[org.eclipse.jetty.server.HttpInputOverHTTP 0x32205a75 HttpInputOverHTTP@32205a75[c=0,q=0,[0]=null,s=EOF]]
       (ok))

As I understand the (:body req) is already consumed somewhere but I don't know where and I'd like to get the output of it. I've read how restructuring works in Compojure api method but it only supports known keys.