Implementing Support for suffixes eg. file extensions
Hi it would be really useful for my use case to support suffixes. e.g. routes like "/users/:id.png"
or even "/users/:id.:ext"
... or even "/users/*.png"
Although it is possible to do at the application level it quickly gets very complicated when multiple extensions are present, and it looks like it might be easier to implement it in Matchit.
According to what I understand from the docs the parameter extends up to the next slash, and so currently is not possible.
How easy would it be to change parameter names to not allow '.' and add something like ParamWithSuffix(String) to the enum NodeType.
I optimistically forked the repo and was planning to implement it but then I realized that I dont understand the code well enough... My fork just has the test case (that currently fails) See below:
use matchit::{InsertError, MatchError, Router};
fn router()->Result<Router<&'static str>,InsertError> {
let mut router = Router::new();
router.insert("/home", "Welcome!")?;
router.insert("/users/:id", "A User")?;
router.insert("/users/:id.png", "A User Photo Currently not working")?;
router.insert("/users/:id/x.png", "Another User Photo that works")?;
Ok(router)
}
#[test]
fn match_img()->Result<(),MatchError>{
let router=router().unwrap();
let matched = router.at("/users/978")?;
assert_eq!(matched.params.get("id"), Some("978"));
assert_eq!(*matched.value, "A User");
Ok(())
}
To consider: how would multiple '.' be handled e.g. schema.foo.yaml
I would be open to adding this feature but it's not really a high priority for me. It might be easier to put some time into writing a param parser at the application level. As a side note, this is the main benefit of the {x} syntax for route parameters...