Fork me on GitHub
#reitit
<
2018-08-08
>
ikitommi08:08:20

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.

ikitommi13:08:06

one more thing that is different from c-api: when to encode responses. comments welcome - https://github.com/metosin/reitit/issues/122

👍 4
valerauko15:08:55

i'd say encode collections + nil, but tbh i don't really understand how 4 and 5 would work

ikitommi15:08:15

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.

👍 4
ikitommi15:08:37

here, the Muuntaja response mw would configure itself for the given endpoint (behind the scenes).

ikitommi15:08:17

for legacy reasons, someone might want to return plain numbers/booleans from an api.

aaron5117:08:31

How would we do optional parameters with schema coercion? Tried (s/maybe s/Int) but still get missing-required-key

ikitommi17:08:58

@aaron51 {(s/optional-key :kikka) s/Int}

aaron5117:08:49

@ikitommi Great! And for default values, would we do that in handler like (get-in req [:parameters :query :x] 10)?

ikitommi17:08:18

@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})

aaron5117:08:26

@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)}}

ikitommi17:08:45

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.

ikitommi17:08:26

so, need to apply defaults manually, before something better pops up. ideas welcome!

aaron5112:08:13

Thanks - we ended up setting parameter defaults while destructuring

aaron5118:08:21

Can we use path parameters to match without the suffix, like "/:image.png"? ^This makes a path parameter called "image.png" instead of "image"

ikitommi18:08:25

currently, no. path-params are only split on /.

aaron5119:08:41

Got it. Thanks for your help @ikitommi!