This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-09
Channels
- # babashka (176)
- # beginners (26)
- # cider (1)
- # cljsrn (3)
- # clojure (60)
- # clojure-australia (3)
- # clojure-europe (8)
- # clojure-uk (3)
- # clojurescript (1)
- # code-reviews (4)
- # community-development (3)
- # cursive (6)
- # depstar (1)
- # emacs (11)
- # figwheel (3)
- # helix (13)
- # integrant (2)
- # jackdaw (1)
- # kaocha (1)
- # leiningen (3)
- # luminus (2)
- # malli (4)
- # music (1)
- # nrepl (2)
- # off-topic (1)
- # practicalli (3)
- # reitit (3)
- # shadow-cljs (16)
- # slack-help (14)
- # sql (13)
- # vim (12)
Hi, does my route config for a POST endpoint looks correct? I’m trying to set it up to accept form URL encoded parameters but it is not working
["/answer/submit" {:post {:parameters {:form [:map [:quiz [:int {:min 0 :max 1}]
:option [:int {:min 0 :max 1}]]]}
:responses {200 {:body string?}
404 {:body string?}
400 {:body string?}}
:handler answer-attempt}}]
(ring/router routes
{:data {:muuntaja muuntaja/instance
:coercion c-malli/coercion
:middleware [mw-muuntaja/format-middleware
rrc/coerce-exceptions-middleware
rrc/coerce-request-middleware
rrc/coerce-response-middleware]}})
✅ 3
With this setup I get error:
{
"schema": "[:map {:closed true} [:quiz [:int {:min 0, :max 1}]]]",
"errors": [
{
"in": [],
"value": null,
"message": "invalid type",
"schema": "[:map {:closed true} [:quiz [:int {:min 0, :max 1}]]]",
"path": [],
"type": "malli.core/invalid-type"
}
],
"value": null,
"type": "reitit.coercion/request-coercion",
"coercion": "malli",
"in": [
"request",
"form-params"
],
"humanized": [
"invalid type"
]
}
Okay I got it working. I had a a few mistakes there.
1) missing reitit.ring.middleware.parameters/parameters-middleware
from the middleware list
2) the :option
parameter should be inside its own vector after :quiz
:
[:map [:quiz [:int {:min 0 :max 10}]]
[:option [:int {:min 0 :max 10}]]]