dream icon indicating copy to clipboard operation
dream copied to clipboard

Match on extension in router

Open ulrikstrid opened this issue 2 years ago • 3 comments

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.

ulrikstrid avatar Feb 10 '22 10:02 ulrikstrid

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;
]

pm-mck avatar Feb 11 '22 21:02 pm-mck

Would it be possible with the same syntax? I.e. /foo/:bar.:ext

yawaramin avatar Feb 12 '22 01:02 yawaramin

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.

aantron avatar Feb 12 '22 02:02 aantron