clojure - Optional query parameters with default value with Compojure (without swagger)? -


i idiomatic way of handling optional query parameters in compojure , assign undefined query parameters default value.

i've tried (which perhaps doesn't work):

(get "/something/:id" [id q :<< as-int :or {q (system/currenttimemillis)}]     ....) 

i'd route match both:

curl /something/123 

and

curl /something/123?q=234542345 

(note similar question has been posted here uses swagger)

there lots of options take. 1 might choose.

(get "/something/:id" req   (let [{:keys [id q] :or {q (system/currenttimemillis)}} (:params req)]      ,,,)) 

ultimately, though, 1 chose depend on whatever led readable (a subjective measurement, that's way goes) code.


Comments