pub struct Router<State> { /* private fields */ }
Expand description
A basic router that can be used to route requests to different services based on the request path.
This router uses matchit::Router
to efficiently match incoming requests
to predefined routes. Each route is associated with an HttpMatcher
and a corresponding service handler.
Implementations§
Source§impl<State> Router<State>
impl<State> Router<State>
Sourcepub fn get<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn get<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a GET route to the router.
the path can contain parameters, e.g. /users/{id}
.
the path can also contain a catch call, e.g. /assets/{*path}
.
Sourcepub fn post<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn post<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a POST route to the router.
Sourcepub fn put<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn put<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a PUT route to the router.
Sourcepub fn delete<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn delete<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a DELETE route to the router.
Sourcepub fn patch<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn patch<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a PATCH route to the router.
Sourcepub fn head<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn head<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a HEAD route to the router.
Sourcepub fn options<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn options<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a OPTIONS route to the router.
Sourcepub fn trace<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn trace<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a TRACE route to the router.
Sourcepub fn connect<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn connect<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a CONNECT route to the router.
Sourcepub fn sub<I, T>(self, prefix: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn sub<I, T>(self, prefix: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
register a nested router under a prefix.
The prefix is used to match the request path and strip it from the request URI.
Sourcepub fn match_route<I, T>(
self,
path: &str,
matcher: HttpMatcher<State, Body>,
service: I,
) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn match_route<I, T>(
self,
path: &str,
matcher: HttpMatcher<State, Body>,
service: I,
) -> Selfwhere
I: IntoEndpointService<State, T>,
add a route to the router with it’s matcher and service.
Sourcepub fn not_found<I, T>(self, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn not_found<I, T>(self, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
use the provided service when no route matches the request.
Trait Implementations§
Source§impl<State> Service<State, Request<Body>> for Router<State>
impl<State> Service<State, Request<Body>> for Router<State>
Auto Trait Implementations§
impl<State> !Freeze for Router<State>
impl<State> !RefUnwindSafe for Router<State>
impl<State> Send for Router<State>
impl<State> Sync for Router<State>
impl<State> Unpin for Router<State>
impl<State> !UnwindSafe for Router<State>
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<State, S, Body> HttpClientExt<State> for S
impl<State, S, Body> HttpClientExt<State> for S
Source§type ExecuteResponse = Response<Body>
type ExecuteResponse = Response<Body>
execute
method.Source§type ExecuteError = <S as Service<State, Request<Body>>>::Error
type ExecuteError = <S as Service<State, Request<Body>>>::Error
execute
method.Source§fn get(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
fn get( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
GET
request to a URL. Read moreSource§fn post(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
fn post( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
POST
request to a URL. Read moreSource§fn put(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
fn put( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
PUT
request to a URL. Read moreSource§fn patch(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
fn patch( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
PATCH
request to a URL. Read moreSource§fn delete(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
fn delete( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
DELETE
request to a URL. Read moreSource§fn head(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
fn head( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
HEAD
request to a URL. Read moreSource§fn request(
&self,
method: Method,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
fn request( &self, method: Method, url: impl IntoUrl, ) -> RequestBuilder<'_, S, State, <S as HttpClientExt<State>>::ExecuteResponse>
Source§fn execute(
&self,
ctx: Context<State>,
request: Request<Body>,
) -> impl Future<Output = Result<<S as HttpClientExt<State>>::ExecuteResponse, <S as HttpClientExt<State>>::ExecuteError>>
fn execute( &self, ctx: Context<State>, request: Request<Body>, ) -> impl Future<Output = Result<<S as HttpClientExt<State>>::ExecuteResponse, <S as HttpClientExt<State>>::ExecuteError>>
Request
. Read moreSource§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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<State, S, R> IntoEndpointService<State, (State, R)> for Swhere
State: Clone + Send + Sync + 'static,
S: Service<State, Request<Body>, Response = R, Error = Infallible>,
R: IntoResponse + Send + Sync + 'static,
impl<State, S, R> IntoEndpointService<State, (State, R)> for Swhere
State: Clone + Send + Sync + 'static,
S: Service<State, Request<Body>, Response = R, Error = Infallible>,
R: IntoResponse + Send + Sync + 'static,
Source§fn into_endpoint_service(
self,
) -> impl Service<State, Request<Body>, Response = Response<Body>, Error = Infallible>
fn into_endpoint_service( self, ) -> impl Service<State, Request<Body>, Response = Response<Body>, Error = Infallible>
rama_core::Service
.