-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl Endpoint for Service, for service nesting #364
Conversation
9f0b9f8
to
4db1e5f
Compare
I wonder if something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch looks good! I think we can probably merge it as-is.
Looking Ahead
I'm curious if we could move forward from here though. Ideally folks could write something like this, and it would just work:
let mut inner = tide::new();
inner.at("/").get(|_| async { "root" });
inner.at("/foo").get(|_| async { "foo" });
inner.at("/bar").get(|_| async { "bar" });
let mut outer = tide::new();
outer.at("/nested").get(inner);
But we'd need to implement two changes for this:
- Either implement
HttpService
forServer
, or introduce a new trait:IntoHttpService
that knows how to convert something into an http service. It'd be neat if we could remove theServer
/Service
distinction. - Make it so we can discern between
Server
and regularEndpoint
s without needing to toggle methods manually. Maybe we could add this as a method onEndpoint
that is called once when passed into a handler.
I think if we put those together, nesting services will become something that will become incredibly intuitive!
@tirr-c oh, also another question: on Discord someone asked whether we supported |
@yoshuawuyts I think this is good to merge now! Marked And yeah, per-route middleware shouldn't be hard to implement. I'll add it as a follow-up. |
This is a half-baked version of nesting. Need to strip the path prefix, but I feel this is a good first step!Nevermind, I managed to write necessary mechanics for nesting.HttpService
impl is refactored to useEndpoint
impl internally.Route::strip_prefix
. When used, this will strip the route path prefix from request before passing it to the endpoint.With this PR, we can finally nest Tide services!
Might need a better name for
strip_prefix
, likeprefixed
?