dream
dream copied to clipboard
Match on extension in router
It would be nice if we could match on a file extension in the router, something like this:
[
Dream.get "/foo/:bar" @@ html_handler;
Dream.get "/foo/:bar.html" @@ html_handler;
Dream.get "/foo/:bar.json" @@ json_handler;
]
The current behaviour is that :bar.html
will be parsed as the parameter name.
Would others find it useful to allow the extension to be a parameter as well? Looking at something like reitit in Clojure, they allow a separate syntax for handling this. In Dream it might look like this:
[
Dream.get "/foo/:bar" @@ html_handler;
Dream.get "/foo/{bar}.{ext}" @@ generic_handler;
]
Would it be possible with the same syntax? I.e. /foo/:bar.:ext
I think it would be best to be able to delimit the variable names somehow, so {bar}
or :{bar}
, etc. Ending a variable name with .
seems too implicit, and too specific to extensions in particular. There might be other reasons why someone wants to have a variable for part of a component.