lunatic-solutions/submillisecond

Add support for wildcard routing `/*`

tqwewe opened this issue · 2 comments

The router should support wildcards with the * character.

The difference between /* and /:foo are the following:

let router = router! {
    GET "/:foo" => ... // matches /id, /hello, /...
    GET "/*" => ... // matches /id, /id/123, /any/thing/here
};

Some questions we need to answer:

  1. Do we want to support /foo-* to catch anything starting with /foo-? Or should * be limited only to directly after the /?
  2. Do we want to name the wildcard with /*id? Similar to matchit.
    I think with our approach, naming the wildcard has no use.

Additionally, we should analyze the paths and error if the user placed a wildcard route above a specific route as it would never match.

router! {
    GET "/*" => any_handler
    GET "/about" => about // error here, since this will never match
}
  1. I think we can easily support /foo-*??, and it would give users more freedom. However, if it would complicate the implementation too much I don't think we need it.
  2. We need to be able to name it, or you would not be able to extract it. Right?

And I like the error catching at compile time, but we can add it at a later point.

We need to be able to name it, or you would not be able to extract it. Right?

Not quite, with matchit, they have it named because their router has all the routes combined into a single struct, so you need a name if I'm not mistaken. But for us, we can just have an extractor RouteTail which just gives the last part of the url. The name doesn't provide much value in our case.