-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make UrlParams public #3017
Comments
This branch adds a method to remove parameters from the request: https://github.com/tokio-rs/axum/compare/main...Diggsey:axum:axum-v0.7.7-patched?expand=1 |
I'm not sure about allowing such changes to the url params. I feel like it could lead to more surprises. But it's true that nested handlers shouldn't have to be concerned about parameters of routers under which they've been nested. Would it be good enough for your use case if we added another I feel like that somewhat follows the design of |
It would solve my use-case, but I think it could be confusing. Especially if Axum already hides what constitutes a single router - for example, when you call It's unclear how such a Path-like extractor would interact with these. Another option would be to provide a fn isolate(self) -> axum::Router<S> {
axum::Router::new().fallback(
|axum::extract::State(state): axum::extract::State<S>,
mut request: axum::extract::Request| async move {
clear_url_params(request.extensions_mut());
self.clone().with_state(state).oneshot(request).await
},
)
} That way you could truly separate two routers. |
It would be of course up to discussion if we should keep the current Calling An example of what I have in mind would be something like: let inner_router = Router::new().route("/:id/:version", |path: Path<(String, String)>| todo!());
let router = Router::new()
.nest("/global/:env", inner_router.clone())
.nest("/customer/:customer_id/:env", inner_router); which would fail because the inner_router cannot expect both 3 or 4 path segments (actually it can if it used |
Feature Request
Make
UrlParams
public.Motivation
I want to be able to nest a router under a dynamic path (
/:foo
) and use a middleware to extract the value of:foo
and do something with it. The middleware should then be able to removefoo
from theUrlParams
so that when it callsNext
, the nested router only sees path parameters that it understands.Proposal
Make
UrlParams
public.Alternatives
Provide a hygenic way to nest a router under a dynamic path.
The text was updated successfully, but these errors were encountered: