This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-15
Channels
- # asami (6)
- # babashka (74)
- # babashka-sci-dev (164)
- # beginners (50)
- # biff (3)
- # calva (71)
- # clj-kondo (4)
- # cljdoc (39)
- # cljsrn (4)
- # clojars (8)
- # clojure (70)
- # clojure-austin (7)
- # clojure-czech (5)
- # clojure-europe (4)
- # clojure-losangeles (1)
- # clojure-nl (10)
- # clojure-norway (1)
- # clojure-uk (3)
- # clojurescript (38)
- # community-development (18)
- # cursive (129)
- # datomic (9)
- # fulcro (7)
- # graalvm (4)
- # improve-getting-started (1)
- # jobs (1)
- # kaocha (2)
- # liberator (9)
- # lsp (22)
- # malli (3)
- # membrane (95)
- # off-topic (86)
- # releases (2)
- # sci (5)
- # specter (2)
I feel I'm missing something. Can I use :malformed?
to check a json POST with spec? And if so, is there some way to only parse the body once and make it available to :post!
?
I'd rather use :processible
instead of malformed. Every decision method can return an updated context, or just a map which will be merged with the context. E.f.
(fn [ctx]
(let [[err value] (-> ctx :request :body (coerce some-schema))
(if value
{:entity value}
[false {:error err}])))
With some hypothetical function coerce
.
Any map value will habe handled like true
for decision function.
In the handlers you can extract the entity or error value from the context as you like.
Ohhhhh? So [false {:error err}] is a vector of the return code and the map to merge into the context?
Which makes sense for malformed? because a map would be true. IOW: yes, it's malformed.
Exactly.
From the docs >Liberator merges a map that is returned from a decision function with the current context. This way we can easily store the value for the choice and retrieve it later in the handle-ok function: (get ctx :choice).
This page should cover it in detail http://clojure-liberator.github.io/liberator/doc/execution-model.html