Open diosney opened 9 years ago
Is there prior art this derives from?
@aredridel Yes, but I don't recall where I saw it.
@aredridel angular ui-router
module has this feature :smile: I know is front-end but at the backend we can give it a good use of it (thought the syntax is different that the one I added above).
I implemented some support for this in path-to-regexp, the library that parses the paths into regular expressions.
My commit is here. I didn't sent a pull request yet as there is no issue related to it in path-to-regexp. I will open one and try to get some feedback.
Interesting. On a (partially related) side note, I did something similar for https://github.com/pillarjs/router/pull/29 (the standalone router, not in Express 4.x) which added support for the RAML type system using https://github.com/mulesoft-labs/raml-path-match. If something like that lands, it would be straightforward to add a new path matching implementation with types (I know URI templates is of some interest too).
Edit: That router is here: https://github.com/mulesoft-labs/osprey-router
I mean, do something like:
which is roughly equivalent to use regex in each case, but the shorthand above is clearer and allows
req.params
to properly type the params, fi:req.params.an_id
would be a number instead of a string.Thanks