This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-08
Channels
- # architecture (8)
- # beginners (78)
- # boot (20)
- # cider (81)
- # clara (53)
- # cljdoc (10)
- # cljsjs (3)
- # clojure (55)
- # clojure-boston (1)
- # clojure-dev (25)
- # clojure-nl (3)
- # clojure-uk (65)
- # clojurescript (65)
- # core-async (1)
- # cursive (41)
- # data-science (4)
- # datomic (16)
- # editors (74)
- # emacs (17)
- # events (1)
- # figwheel (3)
- # hyperfiddle (39)
- # immutant (16)
- # jobs-discuss (62)
- # juxt (2)
- # keechma (2)
- # leiningen (6)
- # mount (7)
- # nrepl (1)
- # off-topic (30)
- # onyx (14)
- # protorepl (2)
- # re-frame (4)
- # reagent (15)
- # reitit (19)
- # shadow-cljs (102)
- # sim-testing (1)
- # spacemacs (44)
- # specter (15)
- # tools-deps (50)
- # vim (2)
the path-parameter decoding fix by @kingmob is merged in master and in 0.2.0-SNAPSHOT
. Re-ran the opensensors perf tests, the average matching time went up from 703ns -> 806ns, now that all path-params are decoded correctly. Compojure has >10000ns, so still quite fast.
one more thing that is different from c-api: when to encode responses. comments welcome - https://github.com/metosin/reitit/issues/122
i'd say encode collections + nil, but tbh i don't really understand how 4 and 5 would work
4&5: as middleware know the endpoint they are attached to at router creation time, they can be configured againt that endpoint. If an endpoint defines {:responses {200 {:body any?}}}
we know that for 200 statuses, we are returning clojure data, that should be always encoded. c-api does this.
here, the Muuntaja response mw would configure itself for the given endpoint (behind the scenes).
for legacy reasons, someone might want to return plain numbers/booleans from an api.
How would we do optional parameters with schema coercion? Tried (s/maybe s/Int) but still get missing-required-key
@ikitommi Great! And for default values, would we do that in handler
like (get-in req [:parameters :query :x] 10)
?
@aaron51 yes, there is a default-coercion-matcher in schema-tools, could add that to schema-coercion in reitit, with it, you can say something like (st/schema s/Int {:default 42})
@ikitommi Almost got it. How do we enable default-coercion-matcher
in reitit?
:coercion reitit.coercion.schema/coercion
:parameters {:query {(s/optional-key :x) (st/default s/Int 10)}}
I could add that to defaults. But to do that yourself, you need to create a new instance of reitit.coercion.schema/coercion
with composed matchers.
oh, it doesn’t add the keys if they are missing, so not that useful: https://github.com/metosin/schema-tools/blob/master/test/cljc/schema_tools/core_test.cljc#L242-L249
so, need to apply defaults manually, before something better pops up. ideas welcome!