pub struct ApiRouter<S = ()> { /* private fields */ }axum only.Expand description
A wrapper over axum::Router that adds
API documentation-specific features.
Implementations§
Source§impl<S> ApiRouter<S>
impl<S> ApiRouter<S>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new router.
See axum::Router::new for details.
Sourcepub fn with_state<S2>(self, state: S) -> ApiRouter<S2>
pub fn with_state<S2>(self, state: S) -> ApiRouter<S2>
Add state to the router.
See axum::Router::with_state for details.
Sourcepub fn with_path_items(
self,
transform: impl FnMut(TransformPathItem<'_>) -> TransformPathItem<'_>,
) -> Self
pub fn with_path_items( self, transform: impl FnMut(TransformPathItem<'_>) -> TransformPathItem<'_>, ) -> Self
Sourcepub fn api_route(self, path: &str, method_router: ApiMethodRouter<S>) -> Self
pub fn api_route(self, path: &str, method_router: ApiMethodRouter<S>) -> Self
Create a route to the given method router and include it in the API documentation.
As opposed to route, this method only accepts an ApiMethodRouter.
See axum::Router::route for details.
Sourcepub fn api_route_with_tsr(
self,
path: &str,
method_router: ApiMethodRouter<S>,
) -> Self
Available on crate feature axum-extra only.
pub fn api_route_with_tsr( self, path: &str, method_router: ApiMethodRouter<S>, ) -> Self
axum-extra only.Create a route to the given method router with trailing slash removal and include it in the API documentation.
As opposed to route_with_tsr, this method only accepts an ApiMethodRouter.
See axum_extra::routing::RouterExt::route_with_tsr for details.
Sourcepub fn api_route_with(
self,
path: &str,
method_router: ApiMethodRouter<S>,
transform: impl FnOnce(TransformPathItem<'_>) -> TransformPathItem<'_>,
) -> Self
pub fn api_route_with( self, path: &str, method_router: ApiMethodRouter<S>, transform: impl FnOnce(TransformPathItem<'_>) -> TransformPathItem<'_>, ) -> Self
Create a route to the given method router and include it in the API documentation.
This method accepts a transform function to edit the generated API documentation with.
See axum::Router::route or api_route for details.
Sourcepub fn api_route_with_tsr_and(
self,
path: &str,
method_router: ApiMethodRouter<S>,
transform: impl FnOnce(TransformPathItem<'_>) -> TransformPathItem<'_>,
) -> Self
Available on crate feature axum-extra only.
pub fn api_route_with_tsr_and( self, path: &str, method_router: ApiMethodRouter<S>, transform: impl FnOnce(TransformPathItem<'_>) -> TransformPathItem<'_>, ) -> Self
axum-extra only.Create a route to the given method router with trailing slash removal and include it in the API documentation.
This method accepts a transform function to edit the generated API documentation with.
See axum_extra::routing::RouterExt::route_with_tsr for details.
Sourcepub fn finish_api(self, api: &mut OpenApi) -> Router<S>
pub fn finish_api(self, api: &mut OpenApi) -> Router<S>
Turn this router into an axum::Router while merging
generated documentation into the provided OpenApi.
Sourcepub fn finish_api_with<F>(self, api: &mut OpenApi, transform: F) -> Router<S>
pub fn finish_api_with<F>(self, api: &mut OpenApi, transform: F) -> Router<S>
Turn this router into an axum::Router while merging
generated documentation into the provided OpenApi.
This method accepts a transform function to edit the generated API documentation with.
Source§impl<S> ApiRouter<S>
Existing methods extended with api-specifics.
impl<S> ApiRouter<S>
Existing methods extended with api-specifics.
Sourcepub fn route(
self,
path: &str,
method_router: impl Into<ApiMethodRouter<S>>,
) -> Self
pub fn route( self, path: &str, method_router: impl Into<ApiMethodRouter<S>>, ) -> Self
See axum::Router::route for details.
This method accepts ApiMethodRouter but does not generate API documentation.
Sourcepub fn route_with_tsr(
self,
path: &str,
method_router: impl Into<ApiMethodRouter<S>>,
) -> Self
Available on crate feature axum-extra only.
pub fn route_with_tsr( self, path: &str, method_router: impl Into<ApiMethodRouter<S>>, ) -> Self
axum-extra only.See axum_extra::routing::RouterExt::route_with_tsr for details.
This method accepts ApiMethodRouter but does not generate API documentation.
Sourcepub fn route_service<T>(self, path: &str, service: T) -> Self
pub fn route_service<T>(self, path: &str, service: T) -> Self
See axum::Router::route_service for details.
Sourcepub fn route_service_with_tsr<T>(self, path: &str, service: T) -> Self
Available on crate feature axum-extra only.
pub fn route_service_with_tsr<T>(self, path: &str, service: T) -> Self
axum-extra only.See axum_extra::routing::RouterExt::route_service_with_tsr for details.
Sourcepub fn nest(self, path: &str, router: ApiRouter<S>) -> Self
pub fn nest(self, path: &str, router: ApiRouter<S>) -> Self
See axum::Router::nest for details.
The generated documentations are nested as well.
Sourcepub fn nest_api_service(
self,
path: &str,
service: impl Into<ApiRouter<()>>,
) -> Self
pub fn nest_api_service( self, path: &str, service: impl Into<ApiRouter<()>>, ) -> Self
Alternative to nest_service which besides nesting the service nests
the generated documentation as well.
Due to Rust’s limitations, currently this function will not
accept arbitrary services but only types that can be
converted into an ApiRouter.
Thus the primary and probably the only use-case of this function is nesting routers with different states.
Sourcepub fn nest_service<T>(self, path: &str, svc: T) -> Self
pub fn nest_service<T>(self, path: &str, svc: T) -> Self
See axum::Router::nest_service for details. Use nest_api_service
to pass on the API documentation from the nested service as well.
Sourcepub fn merge<R>(self, other: R) -> Self
pub fn merge<R>(self, other: R) -> Self
See axum::Router::merge for details.
If an another ApiRouter is provided, the generated documentations
are merged as well..
Sourcepub fn layer<L>(self, layer: L) -> ApiRouter<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request<Body>> + Clone + Send + Sync + 'static,
<L::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
pub fn layer<L>(self, layer: L) -> ApiRouter<S>where
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request<Body>> + Clone + Send + Sync + 'static,
<L::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
See axum::Router::layer for details.
Sourcepub fn route_layer<L>(self, layer: L) -> Selfwhere
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request<Body>> + Clone + Send + Sync + 'static,
<L::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
pub fn route_layer<L>(self, layer: L) -> Selfwhere
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request<Body>> + Clone + Send + Sync + 'static,
<L::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
See axum::Router::route_layer for details.
Sourcepub fn fallback<H, T>(self, handler: H) -> Selfwhere
H: Handler<T, S>,
T: 'static,
pub fn fallback<H, T>(self, handler: H) -> Selfwhere
H: Handler<T, S>,
T: 'static,
See axum::Router::fallback for details.
Sourcepub fn fallback_service<T>(self, svc: T) -> Self
pub fn fallback_service<T>(self, svc: T) -> Self
See axum::Router::fallback_service for details.
Sourcepub fn as_service<B>(&mut self) -> RouterAsService<'_, B, S>
pub fn as_service<B>(&mut self) -> RouterAsService<'_, B, S>
See axum::Router::as_service for details.
Using this method will not generate API documentation.
Sourcepub fn into_service<B>(self) -> RouterIntoService<B, S>
pub fn into_service<B>(self) -> RouterIntoService<B, S>
See axum::Router::into_service for details.
Using this method will not generate API documentation.
Source§impl ApiRouter<()>
impl ApiRouter<()>
Sourcepub fn into_make_service(self) -> IntoMakeService<Router<()>>
pub fn into_make_service(self) -> IntoMakeService<Router<()>>
See axum::Router::into_make_service for details.
Sourcepub fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<Router<()>, C>
Available on crate feature axum-tokio only.
pub fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<Router<()>, C>
axum-tokio only.See axum::Router::into_make_service_with_connect_info for details.
Trait Implementations§
Source§impl<B> Service<Request<B>> for ApiRouter<()>
impl<B> Service<Request<B>> for ApiRouter<()>
Source§type Error = Infallible
type Error = Infallible
Source§type Future = RouteFuture<Infallible>
type Future = RouteFuture<Infallible>
Auto Trait Implementations§
impl<S> Freeze for ApiRouter<S>
impl<S = ()> !RefUnwindSafe for ApiRouter<S>
impl<S> Send for ApiRouter<S>
impl<S> Sync for ApiRouter<S>
impl<S> Unpin for ApiRouter<S>
impl<S = ()> !UnwindSafe for ApiRouter<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
Source§fn into_make_service(self) -> IntoMakeService<S>
fn into_make_service(self) -> IntoMakeService<S>
MakeService, that is a Service whose
response is another service. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<S, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<S, C>
tokio only.MakeService, that will store C’s
associated ConnectInfo in a request extension such that ConnectInfo
can extract it. Read moreSource§fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
HandleError, that will handle errors
by converting them into responses. Read moreSource§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
Source§fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
Source§fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
Source§fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
Service, calling it with the provided request once it is ready.Source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready method. Read moreSource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready method. Read moreSource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready method. Read moreSource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>)
to a different value, regardless of whether the future succeeds or
fails. Read more