Fork me on GitHub
#reitit
<
2021-02-01
>
taylskid20:02:01

I would like to utilize comma-separated query parameters instead of repeating the key for each element, i.e. ?foo=bar,baz instead of ?foo=bar&foo=baz . I haven't been able to find any configuration option or obvious examples over a few Google queries. Does anyone have any experience with trying this? Or should I just accept the defaults as they are 😅

dharrigan20:02:47

I use comma separated queries

dharrigan20:02:46

Basically I have this:

dharrigan20:02:05

(def paging [:map
             {:closed true}
             [:limit {:optional true :default 25} [:int {:min 0 :max 100}]]
             [:page {:optional true :default 0} [:int {:min 0 :max 500}]]
             [:sort {:optional true} [:enum {:swagger/type "string"} "asc" "desc"]]
             [:sort-fields {:optional true} string?]
             [:fields {:optional true} string?]])

dharrigan20:02:24

fields is just a string..

dharrigan20:02:27

then when I process it...

dharrigan20:02:14

(let [{{{:keys [ fields]} :query} :parameters} request]
    {:fields (when-not (clojure.string/blank? fields) (clojure.string/split fields ",")}

dharrigan20:02:03

I end up with a :fields key in a map with [bar baz]

dharrigan20:02:11

process then as you see fit 🙂

dharrigan20:02:42

btw, I use malli

dharrigan20:02:25

in your case, :fields would be :foo

taylskid20:02:01

okay, I figured something like that would work, I was just hoping there was a built in way to have reitit coerce things nicely just in [:parameters :query]

dharrigan20:02:24

not aware of anything 😉 Supaar simple to do oneself, tho 🙂

dharrigan20:02:45

maybe, worth a try

dharrigan20:02:23

if you were to change the spec to be :fields {optional true} [:vector string?]

dharrigan20:02:34

that may coerce it into a vector?

dharrigan20:02:42

give it a shot

taylskid20:02:50

I already have the spec defined as a vector, but the only way it coerces right now is if I pass them in like ?foo=bar&foo=baz