You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WebService: this is using boxed handlers and comes with the benefits of nice regular Rust
match_service! macro: this is same-same but using tuples and thus no need to Box. It is however a bit less easy to use for first time users
Both are very flexible in that they allow you to match on pretty much anything. However for a traditional web server it is a lot nicer to work with a trie-like structure to match purely on paths. You could still mix-and-match that with the two approaches above in case you want to specialise further (e.g. method) once you are in a path. This is possible as the two above still result in a Service (https://docs.rs/rama/latest/rama/trait.Service.html), which is also an EndpointService (https://docs.rs/rama/latest/rama/http/service/web/trait.IntoEndpointService.html)
You could also go fancier and create also some kind of RoutingService which could wrap the WebService and makes it a lot easier to chain based on common matchers such as methods etc, for same path. But that's more of an extra.
Which would allow you to make it look more like:
use rama::http::service::web::{Router, routing::get};let app = Router::new().route("/",get(root)).route("/users",get(list_users).post(create_user)).route("/users",get(create_user)).route("/users/{id}",get(show_user)).route("/assets/{*path}",get(serve_asset));
Might be nicer and easier to implement, something to think about.
The text was updated successfully, but these errors were encountered:
I had a look at the two methods, using WebService boxed handlers and the match_service! macro. As of now, I will start building Router and get that done as a v1 task. Once I am satisfied with those results, I will also have a crack at the RoutingService way (that feels more intuitive so would be nice to have that solution as well).
Sounds good. Do let me know if you need feedback, have questions or want to bounce some ideas around. Do also feel free to open a draft PR if you are stuck or require (early) feedback, all good.
Hey @GlenDC , so this implementation would basically be a wrapper around matchit right?
Also maybe a silly doubt, but does the current implementation handle the params feature in a route? Because if it does not, then we would have to write a separate matcher service as well right which would provide a function to extract params from the route? Can you please tell me if this is right or I am going wrong somewhere?
There's already a Matcher approach in https://docs.rs/rama/latest/rama/http/service/web/index.html, in two ways:
match_service!
macro: this is same-same but using tuples and thus no need to Box. It is however a bit less easy to use for first time usersBoth are very flexible in that they allow you to match on pretty much anything. However for a traditional web server it is a lot nicer to work with a trie-like structure to match purely on paths. You could still mix-and-match that with the two approaches above in case you want to specialise further (e.g. method) once you are in a path. This is possible as the two above still result in a
Service
(https://docs.rs/rama/latest/rama/trait.Service.html), which is also anEndpointService
(https://docs.rs/rama/latest/rama/http/service/web/trait.IntoEndpointService.html)The
Router
has to implement theService
trait (https://docs.rs/rama/latest/rama/trait.Service.html), which will be very similar to how https://docs.rs/rama/latest/rama/http/service/web/struct.WebService.html#impl-Service%3CState,+Request%3CBody%3E%3E-for-WebService%3CState%3E does it, except that you would do it using an approach focussed on paths. These paths should support extraction of segment data and wildcards out of the box and inject them similar to how a PatchMatcher (https://docs.rs/rama/latest/rama/http/matcher/struct.PathMatcher.html) does it.API interface could look like:
As part of implementing this
Router
you can addmatchit
as a dependency: https://docs.rs/matchit/latest/matchit/You could also go fancier and create also some kind of
RoutingService
which could wrap theWebService
and makes it a lot easier to chain based on common matchers such as methods etc, for same path. But that's more of an extra.Which would allow you to make it look more like:
Might be nicer and easier to implement, something to think about.
The text was updated successfully, but these errors were encountered: