reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
taylskid 2021-02-01T20:32:01.059400Z

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 😅

dharrigan 2021-02-01T20:39:47.059700Z

I use comma separated queries

dharrigan 2021-02-01T20:40:46.060100Z

Basically I have this:

dharrigan 2021-02-01T20:41:05.060300Z

(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?]])

dharrigan 2021-02-01T20:41:24.060700Z

fields is just a string..

dharrigan 2021-02-01T20:41:27.060900Z

then when I process it...

dharrigan 2021-02-01T20:43:14.062400Z

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

dharrigan 2021-02-01T20:44:03.063500Z

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

dharrigan 2021-02-01T20:44:11.063700Z

process then as you see fit 🙂

dharrigan 2021-02-01T20:44:42.063900Z

btw, I use malli

dharrigan 2021-02-01T20:45:25.064300Z

in your case, :fields would be :foo

taylskid 2021-02-01T20:46:01.064900Z

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]

dharrigan 2021-02-01T20:46:24.065300Z

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

dharrigan 2021-02-01T20:46:45.065500Z

maybe, worth a try

dharrigan 2021-02-01T20:47:23.066300Z

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

dharrigan 2021-02-01T20:47:34.066600Z

that may coerce it into a vector?

dharrigan 2021-02-01T20:47:42.066800Z

give it a shot

taylskid 2021-02-01T20:49:50.067600Z

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

dharrigan 2021-02-01T20:49:57.067800Z

k