Not actually at a REPL, but isn't this as straightforward as returning nil from html/display-thing if there's no id element in my-map? Take a look at (source GET) to see how the macro passes control to the next route if the method or URL don't match.
Check if URL parameter exists in map
Question
(defroutes my-routes
(GET "/:id" [id] (html/display-thing id)))
(def my-map
{:id 1 :title "One"
:id 2 :title "Two"})
Is there a nice way to check if the url parameter id
exists in my-map
else continue checking if the other routes match? I know you can do something similar with regex like so: ["/:id", :id #"[0-9]+"]
and suspect it might be possible to plug in an arbitrary predicate function.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow