seanmonstar / warp

A super-easy, composable, web server framework for warp speeds.
https://seanmonstar.com/post/176530511587/warp
MIT License
9.57k stars 717 forks source link

Route based on path suffix #808

Open jonsecchis opened 3 years ago

jonsecchis commented 3 years ago

Is your feature request related to a problem? Please describe.

Currently, all routing abstractions are limited by:

let route = warp::path("x"); // Prefix style + Well known segments
let route = warp::path!("some" / String); // Prefix style + Fixed arity + Well known segments

So, there is no easy way to match a path based on its suffix if the segments structure is not well known.

Describe the solution you'd like

A method to capture a request based on a path suffix for any arbitrary path structure, such that all of a.ext, a/b.ext and b/c.ext reach the same route.

jxs commented 3 years ago

Hi, you can use a type to match the prefix, see https://github.com/seanmonstar/warp/issues/19#issuecomment-410392693

jonsecchis commented 3 years ago

Hi, you can use a type to match the prefix, see #19 (comment)

I'm aware of that method, and it is a good one. But is suffers from the problem of fixed arity, since the count of path parameters must be fixed.

I come to the conclusion that a simple regex filter would be the way to go, since it would enable this suffix use case and many many others.

mehmooda commented 3 years ago

A simple segments(isize) filter would be nice.

If you pass segments(2) it'll extract the first 2 segments. and allow path based matching on the rest. if you pass segments(-2) it'll extract all segments apart from the last 2.

Can be used to implement suffix. Also the extracted value can be used to determine the "app root" if that's required for the service.