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<State> WebService<State>
impl<State> WebService<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 web service, using the given service.
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 web service, using the given service.
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 web service, using the given service.
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 web service, using the given service.
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 web service, using the given service.
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 web service, using the given service.
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 web service, using the given service.
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 web service, using the given service.
Sourcepub fn nest<I, T>(self, prefix: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn nest<I, T>(self, prefix: &str, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
nest a web service under the given path.
The nested service will receive a request with the path prefix removed.
Sourcepub fn dir(self, prefix: &str, dir: &str) -> Self
pub fn dir(self, prefix: &str, dir: &str) -> Self
serve the given directory under the given path.
Sourcepub fn on<I, T>(self, matcher: HttpMatcher<State, Body>, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
pub fn on<I, T>(self, matcher: HttpMatcher<State, Body>, service: I) -> Selfwhere
I: IntoEndpointService<State, T>,
add a route to the web service which matches the given matcher, using the given 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 given service in case no match could be found.
Trait Implementations§
Source§impl<State> Clone for WebService<State>
impl<State> Clone for WebService<State>
Source§impl<State> Debug for WebService<State>
impl<State> Debug for WebService<State>
Source§impl<State> Default for WebService<State>
impl<State> Default for WebService<State>
Source§impl<State> Service<State, Request<Body>> for WebService<State>
impl<State> Service<State, Request<Body>> for WebService<State>
Auto Trait Implementations§
impl<State> Freeze for WebService<State>
impl<State> !RefUnwindSafe for WebService<State>
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> !UnwindSafe for WebService<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> 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<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
.