pub struct WebService<State = ()> { /* private fields */ }Expand description
A basic web service that can be used to serve HTTP requests.
Note that this service boxes all the internal services, so it is not as efficient as it could be.
For those locations where you need do not desire the convenience over performance,
you can instead use a tuple of (M, S) tuples, where M is a matcher and S is a service,
e.g. ((MethodMatcher::GET, service_a), (MethodMatcher::POST, service_b), service_fallback).
Implementations§
Source§impl WebService
impl WebService
Source§impl<State> WebService<State>
impl<State> WebService<State>
pub fn new_with_state(state: State) -> Self
Sourcepub fn with_get<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_get<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a GET route to the web service, using the given service.
Sourcepub fn set_get<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_get<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a GET route to the web service, using the given service.
Sourcepub fn with_post<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_post<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a POST route to the web service, using the given service.
Sourcepub fn set_post<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_post<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a POST route to the web service, using the given service.
Sourcepub fn with_put<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_put<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a PUT route to the web service, using the given service.
Sourcepub fn set_put<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_put<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a PUT route to the web service, using the given service.
Sourcepub fn with_delete<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_delete<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a DELETE route to the web service, using the given service.
Sourcepub fn set_delete<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_delete<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a DELETE route to the web service, using the given service.
Sourcepub fn with_patch<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_patch<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a PATCH route to the web service, using the given service.
Sourcepub fn set_patch<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_patch<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a PATCH route to the web service, using the given service.
Sourcepub fn with_head<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_head<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a HEAD route to the web service, using the given service.
Sourcepub fn set_head<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_head<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a HEAD route to the web service, using the given service.
Sourcepub fn with_options<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_options<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a OPTIONS route to the web service, using the given service.
Sourcepub fn set_options<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_options<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a OPTIONS route to the web service, using the given service.
Sourcepub fn with_trace<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_trace<I, T>(self, path: &str, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a TRACE route to the web service, using the given service.
Sourcepub fn set_trace<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_trace<I, T>(&mut self, path: &str, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a TRACE route to the web service, using the given service.
Sourcepub fn with_nest_make_fn(
self,
prefix: &str,
configure_svc: impl FnOnce(Self) -> Self,
) -> Self
pub fn with_nest_make_fn( self, prefix: &str, configure_svc: impl FnOnce(Self) -> Self, ) -> Self
Nest a web service under the given path.
The nested service will receive a request with the path prefix removed.
Note: this sub-webservice is configured with the same State this router has.
Sourcepub fn set_nest_make_fn(
&mut self,
prefix: &str,
configure_svc: impl FnOnce(Self) -> Self,
) -> &mut Self
pub fn set_nest_make_fn( &mut self, prefix: &str, configure_svc: impl FnOnce(Self) -> Self, ) -> &mut Self
Nest a web service under the given path.
The nested service will receive a request with the path prefix removed.
Note: this sub-webservice is configured with the same State this router has.
Sourcepub fn with_nest_service<I, T>(
self,
prefix: impl AsRef<str>,
service: I,
) -> Selfwhere
I: IntoEndpointService<T>,
I::Service: Service<Request, Output = Response, Error = Infallible>,
pub fn with_nest_service<I, T>(
self,
prefix: impl AsRef<str>,
service: I,
) -> Selfwhere
I: IntoEndpointService<T>,
I::Service: Service<Request, Output = Response, Error = Infallible>,
Nest a web service under the given path.
The nested service will receive a request with the path prefix removed.
Warning: This sub-service has no notion of the state this webservice has. If you want to create a nested-service that shares the same state this webservice has, use WebService::set_nest_make_fn instead.
Sourcepub fn set_nest_service<I, T>(
&mut self,
prefix: impl AsRef<str>,
service: I,
) -> &mut Selfwhere
I: IntoEndpointService<T>,
I::Service: Service<Request, Output = Response, Error = Infallible>,
pub fn set_nest_service<I, T>(
&mut self,
prefix: impl AsRef<str>,
service: I,
) -> &mut Selfwhere
I: IntoEndpointService<T>,
I::Service: Service<Request, Output = Response, Error = Infallible>,
Nest a web service under the given path.
The nested service will receive a request with the path prefix removed.
Warning: This sub-service has no notion of the state this webservice has. If you want to create a nested-service that shares the same state this webservice has, use WebService::set_nest_make_fn instead.
Sourcepub fn with_file(self, prefix: &str, path: impl AsRef<Path>, mime: Mime) -> Self
pub fn with_file(self, prefix: &str, path: impl AsRef<Path>, mime: Mime) -> Self
serve the given file under the given path.
Sourcepub fn set_file(
&mut self,
prefix: &str,
path: impl AsRef<Path>,
mime: Mime,
) -> &mut Self
pub fn set_file( &mut self, prefix: &str, path: impl AsRef<Path>, mime: Mime, ) -> &mut Self
serve the given file under the given path.
Sourcepub fn with_dir(self, prefix: &str, path: impl AsRef<Path>) -> Self
pub fn with_dir(self, prefix: &str, path: impl AsRef<Path>) -> Self
serve the given directory under the given path.
Sourcepub fn set_dir(&mut self, prefix: &str, path: impl AsRef<Path>) -> &mut Self
pub fn set_dir(&mut self, prefix: &str, path: impl AsRef<Path>) -> &mut Self
serve the given directory under the given path.
Sourcepub fn with_dir_with_serve_mode(
self,
prefix: &str,
path: impl AsRef<Path>,
mode: DirectoryServeMode,
) -> Self
pub fn with_dir_with_serve_mode( self, prefix: &str, path: impl AsRef<Path>, mode: DirectoryServeMode, ) -> Self
serve the given directory under the given path, with a custom serve move.
Sourcepub fn set_dir_with_serve_mode(
&mut self,
prefix: &str,
path: impl AsRef<Path>,
mode: DirectoryServeMode,
) -> &mut Self
pub fn set_dir_with_serve_mode( &mut self, prefix: &str, path: impl AsRef<Path>, mode: DirectoryServeMode, ) -> &mut Self
serve the given directory under the given path, with a custom serve move.
Sourcepub fn with_dir_embed(self, prefix: &str, dir: Dir<'static>) -> Self
pub fn with_dir_embed(self, prefix: &str, dir: Dir<'static>) -> Self
serve the given embedded directory under the given path.
Sourcepub fn set_dir_embed(&mut self, prefix: &str, dir: Dir<'static>) -> &mut Self
pub fn set_dir_embed(&mut self, prefix: &str, dir: Dir<'static>) -> &mut Self
serve the given embedded directory under the given path.
Sourcepub fn with_dir_embed_with_serve_mode(
self,
prefix: &str,
dir: Dir<'static>,
mode: DirectoryServeMode,
) -> Self
pub fn with_dir_embed_with_serve_mode( self, prefix: &str, dir: Dir<'static>, mode: DirectoryServeMode, ) -> Self
serve the given embedded directory under the given path with a custom serve move.
Sourcepub fn set_dir_embed_with_serve_mode(
&mut self,
prefix: &str,
dir: Dir<'static>,
mode: DirectoryServeMode,
) -> &mut Self
pub fn set_dir_embed_with_serve_mode( &mut self, prefix: &str, dir: Dir<'static>, mode: DirectoryServeMode, ) -> &mut Self
serve the given embedded directory under the given path with a custom serve move.
Sourcepub fn with_matcher<I, T>(self, matcher: HttpMatcher<Body>, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_matcher<I, T>(self, matcher: HttpMatcher<Body>, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a route to the web service which matches the given matcher, using the given service.
Sourcepub fn set_matcher<I, T>(
&mut self,
matcher: HttpMatcher<Body>,
service: I,
) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_matcher<I, T>(
&mut self,
matcher: HttpMatcher<Body>,
service: I,
) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
add a route to the web service which matches the given matcher, using the given service.
Sourcepub fn with_not_found<I, T>(self, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn with_not_found<I, T>(self, service: I) -> Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
use the given service in case no match could be found.
Sourcepub fn set_not_found<I, T>(&mut self, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
pub fn set_not_found<I, T>(&mut self, service: I) -> &mut Selfwhere
I: IntoEndpointServiceWithState<T, State>,
I::Service: Service<Request, Output: IntoResponse, Error: Into<ErrorResponse>>,
use the given service in case no match could be found.
Trait Implementations§
Source§impl<State: Clone> Clone for WebService<State>
impl<State: Clone> Clone for WebService<State>
Source§fn clone(&self) -> WebService<State>
fn clone(&self) -> WebService<State>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<State: Debug> Debug for WebService<State>
impl<State: Debug> Debug for WebService<State>
Source§impl Default for WebService
impl Default for WebService
Auto Trait Implementations§
impl<State = ()> !RefUnwindSafe for WebService<State>
impl<State = ()> !UnwindSafe for WebService<State>
impl<State> Freeze for WebService<State>where
State: Freeze,
impl<State> Send for WebService<State>where
State: Send,
impl<State> Sync for WebService<State>where
State: Sync,
impl<State> Unpin for WebService<State>where
State: Unpin,
impl<State> UnsafeUnpin for WebService<State>where
State: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<S, Body> HttpClientExt for S
impl<S, Body> HttpClientExt for S
Source§type ExecuteResponse = Response<Body>
type ExecuteResponse = Response<Body>
execute method.Source§type ExecuteError = <S as Service<Request>>::Error
type ExecuteError = <S as Service<Request>>::Error
execute method.Source§fn get(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn get( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
GET request to a URL. Read moreSource§fn post(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn post( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
POST request to a URL. Read moreSource§fn put(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn put( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
PUT request to a URL. Read moreSource§fn patch(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn patch( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
PATCH request to a URL. Read moreSource§fn delete(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn delete( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
DELETE request to a URL. Read moreSource§fn head(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn head( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
HEAD request to a URL. Read moreSource§fn connect(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn connect( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
CONNECT request to a URL. Read moreSource§fn request(
&self,
method: Method,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn request( &self, method: Method, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
Source§fn build_from_request<RequestBody>(
&self,
request: Request<RequestBody>,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn build_from_request<RequestBody>( &self, request: Request<RequestBody>, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
Source§fn execute(
&self,
request: Request,
) -> impl Future<Output = Result<<S as HttpClientExt>::ExecuteResponse, <S as HttpClientExt>::ExecuteError>>
fn execute( &self, request: Request, ) -> impl Future<Output = Result<<S as HttpClientExt>::ExecuteResponse, <S as HttpClientExt>::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<S> IntoEndpointService<(S,)> for S
impl<S> IntoEndpointService<(S,)> for S
type Service = S
Source§fn into_endpoint_service(self) -> <S as IntoEndpointService<(S,)>>::Service
fn into_endpoint_service(self) -> <S as IntoEndpointService<(S,)>>::Service
rama_core::Service.Source§impl<S, State> IntoEndpointServiceWithState<(S,), State> for S
impl<S, State> IntoEndpointServiceWithState<(S,), State> for S
type Service = S
Source§fn into_endpoint_service_with_state(
self,
_state: State,
) -> <S as IntoEndpointServiceWithState<(S,), State>>::Service
fn into_endpoint_service_with_state( self, _state: State, ) -> <S as IntoEndpointServiceWithState<(S,), State>>::Service
rama_core::Service with state.