Trait axum_extra::routing::RouterExt
source · pub trait RouterExt<S, B>: Sealed {
fn typed_get<H, T, P>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath;
fn typed_delete<H, T, P>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath;
fn typed_head<H, T, P>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath;
fn typed_options<H, T, P>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath;
fn typed_patch<H, T, P>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath;
fn typed_post<H, T, P>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath;
fn typed_put<H, T, P>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath;
fn typed_trace<H, T, P>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath;
fn route_with_tsr(self, path: &str, method_router: MethodRouter<S, B>) -> Self
where
Self: Sized;
fn route_service_with_tsr<T>(self, path: &str, service: T) -> Self
where
T: Service<Request<B>, Error = Infallible> + Clone + Send + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
Self: Sized;
}
Expand description
Extension trait that adds additional methods to Router
.
Required Methods§
sourcefn typed_get<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_get<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.sourcefn typed_delete<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_delete<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.sourcefn typed_head<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_head<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.sourcefn typed_options<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_options<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.sourcefn typed_patch<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_patch<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.sourcefn typed_post<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_post<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.sourcefn typed_put<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_put<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.sourcefn typed_trace<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_trace<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.sourcefn route_with_tsr(self, path: &str, method_router: MethodRouter<S, B>) -> Selfwhere
Self: Sized,
fn route_with_tsr(self, path: &str, method_router: MethodRouter<S, B>) -> Selfwhere
Self: Sized,
Add another route to the router with an additional “trailing slash redirect” route.
If you add a route without a trailing slash, such as /foo
, this method will also add a
route for /foo/
that redirects to /foo
.
If you add a route with a trailing slash, such as /bar/
, this method will also add a
route for /bar
that redirects to /bar/
.
This is similar to what axum 0.5.x did by default, except this explicitly adds another
route, so trying to add a /foo/
route after calling .route_with_tsr("/foo", /* ... */)
will result in a panic due to route overlap.
Example
use axum::{Router, routing::get};
use axum_extra::routing::RouterExt;
let app = Router::new()
// `/foo/` will redirect to `/foo`
.route_with_tsr("/foo", get(|| async {}))
// `/bar` will redirect to `/bar/`
.route_with_tsr("/bar/", get(|| async {}));
sourcefn route_service_with_tsr<T>(self, path: &str, service: T) -> Selfwhere
T: Service<Request<B>, Error = Infallible> + Clone + Send + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
Self: Sized,
fn route_service_with_tsr<T>(self, path: &str, service: T) -> Selfwhere
T: Service<Request<B>, Error = Infallible> + Clone + Send + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
Self: Sized,
Add another route to the router with an additional “trailing slash redirect” route.
This works like RouterExt::route_with_tsr
but accepts any Service
.
Implementations on Foreign Types§
source§impl<S, B> RouterExt<S, B> for Router<S, B>where
B: HttpBody + Send + 'static,
S: Clone + Send + Sync + 'static,
impl<S, B> RouterExt<S, B> for Router<S, B>where
B: HttpBody + Send + 'static,
S: Clone + Send + Sync + 'static,
source§fn typed_get<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_get<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.source§fn typed_delete<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_delete<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.source§fn typed_head<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_head<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.source§fn typed_options<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_options<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.source§fn typed_patch<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_patch<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.source§fn typed_post<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_post<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.source§fn typed_put<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_put<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.source§fn typed_trace<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
fn typed_trace<H, T, P>(self, handler: H) -> Selfwhere
H: Handler<T, S, B>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
typed-routing
only.