metosin / metosin/compojure-api

Can't access whole form parameter list during handler execution

Open
#442 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
1.1k
Forks
146
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the POST "/api/:variable" handler example and the linked Stack Overflow question, then trace where the Ring request body is consumed before handler execution. Done means establishing and documenting a supported way to access the complete form parameters or raw body during the handler.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.