Coercion on route path and query paramaters
drewverlee opened this issue · comments
Greetings,
It would seem ideal to have coercion and defaults for path parameters and query parameters be expressed at the routing level so that downstream logic could share. I don't any documentation around this option and was wondering what should be done. My current plan is to add data to my route tree leafs containing the coercion and defaults and then search that tree for that information before passing it to our app db. One challenge here is that the structure of the bidi routes is unclear to me. e.g
["/" {...}] vs [{...}]
So it's not clear how i could universal search the tree. Let me know if you have any advice on this or on the wider topic. Maybe i should be thinking in terms of middleware?
Thanks, Drew.
Bidi doesn't deal with query parameters, so those are probably going to be a problem to solve in user space. For coercing path parameters you can implement the pattern segment protocol. This allows you to implement custom processing for patterns.
The function implementation is a little harder to follow than I'd like for an example, as it's using cond
, but serves as a good example of handling a few common cases (longs, uuids, etc.). I know you're plenty skilled with Clojure to follow it though!
Thanks Drew, please follow up if you have any more questions.