pub trait Endpoint: Send + Sync {
type Output: IntoResponse;
fn call<'life0, 'async_trait>(
&'life0 self,
req: Request
) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
fn get_response<'life0, 'async_trait>(
&'life0 self,
req: Request
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait,
{ ... }
}
Expand description
An HTTP request handler.
Associated Types
type Output: IntoResponse
type Output: IntoResponse
Represents the response of the endpoint.
Required methods
Provided methods
Get the response to the request and return a Response
.
Unlike Endpoint::call
, when an error occurs, it will also convert
the error into a response object.
Example
use poem::{error::NotFoundError, handler, http::StatusCode, Endpoint, Request, Result};
#[handler]
fn index() -> Result<()> {
Err(NotFoundError.into())
}
let resp = index.get_response(Request::default()).await;
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
Implementations on Foreign Types
Implementors
sourceimpl Endpoint for StaticFileEndpoint
impl Endpoint for StaticFileEndpoint
sourceimpl Endpoint for StaticFilesEndpoint
impl Endpoint for StaticFilesEndpoint
sourceimpl Endpoint for RouteDomain
impl Endpoint for RouteDomain
sourceimpl Endpoint for RouteMethod
impl Endpoint for RouteMethod
sourceimpl Endpoint for RouteScheme
impl Endpoint for RouteScheme
sourceimpl<E, F, ErrType> Endpoint for InspectError<E, F, ErrType> where
E: Endpoint,
F: Fn(&ErrType) + Send + Sync,
ErrType: Error + Send + Sync + 'static,
impl<E, F, ErrType> Endpoint for InspectError<E, F, ErrType> where
E: Endpoint,
F: Fn(&ErrType) + Send + Sync,
ErrType: Error + Send + Sync + 'static,
sourceimpl<E, F, Fut> Endpoint for Before<E, F> where
E: Endpoint,
F: Fn(Request) -> Fut + Send + Sync,
Fut: Future<Output = Result<Request>> + Send,
impl<E, F, Fut> Endpoint for Before<E, F> where
E: Endpoint,
F: Fn(Request) -> Fut + Send + Sync,
Fut: Future<Output = Result<Request>> + Send,
sourceimpl<E, F, Fut, R> Endpoint for CatchAllError<E, F, R> where
E: Endpoint,
F: Fn(Error) -> Fut + Send + Sync,
Fut: Future<Output = R> + Send,
R: IntoResponse + Send + Sync,
impl<E, F, Fut, R> Endpoint for CatchAllError<E, F, R> where
E: Endpoint,
F: Fn(Error) -> Fut + Send + Sync,
Fut: Future<Output = R> + Send,
R: IntoResponse + Send + Sync,
sourceimpl<E, F, Fut, R, ErrType> Endpoint for CatchError<E, F, R, ErrType> where
E: Endpoint,
F: Fn(ErrType) -> Fut + Send + Sync,
Fut: Future<Output = R> + Send,
R: IntoResponse + Send + Sync,
ErrType: Error + Send + Sync + 'static,
impl<E, F, Fut, R, ErrType> Endpoint for CatchError<E, F, R, ErrType> where
E: Endpoint,
F: Fn(ErrType) -> Fut + Send + Sync,
Fut: Future<Output = R> + Send,
R: IntoResponse + Send + Sync,
ErrType: Error + Send + Sync + 'static,
sourceimpl<E, F, Fut, R, R2> Endpoint for AndThen<E, F> where
E: Endpoint<Output = R>,
F: Fn(R) -> Fut + Send + Sync,
Fut: Future<Output = Result<R2>> + Send,
R: IntoResponse,
R2: IntoResponse,
impl<E, F, Fut, R, R2> Endpoint for AndThen<E, F> where
E: Endpoint<Output = R>,
F: Fn(R) -> Fut + Send + Sync,
Fut: Future<Output = Result<R2>> + Send,
R: IntoResponse,
R2: IntoResponse,
type Output = R2
sourceimpl<E, F, Fut, R, R2> Endpoint for Map<E, F> where
E: Endpoint<Output = R>,
F: Fn(R) -> Fut + Send + Sync,
Fut: Future<Output = R2> + Send,
R: IntoResponse,
R2: IntoResponse,
impl<E, F, Fut, R, R2> Endpoint for Map<E, F> where
E: Endpoint<Output = R>,
F: Fn(R) -> Fut + Send + Sync,
Fut: Future<Output = R2> + Send,
R: IntoResponse,
R2: IntoResponse,
type Output = R2
sourceimpl<E, F, Fut, T> Endpoint for After<E, F> where
E: Endpoint,
F: Fn(Result<E::Output>) -> Fut + Send + Sync,
Fut: Future<Output = Result<T>> + Send,
T: IntoResponse,
impl<E, F, Fut, T> Endpoint for After<E, F> where
E: Endpoint,
F: Fn(Result<E::Output>) -> Fut + Send + Sync,
Fut: Future<Output = Result<T>> + Send,
T: IntoResponse,
type Output = T
sourceimpl<E, F, Fut, T> Endpoint for Around<E, F> where
E: Endpoint,
F: Fn(Arc<E>, Request) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<T>> + Send,
T: IntoResponse,
impl<E, F, Fut, T> Endpoint for Around<E, F> where
E: Endpoint,
F: Fn(Arc<E>, Request) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<T>> + Send,
T: IntoResponse,
type Output = T
sourceimpl<E, T> Endpoint for AddDataEndpoint<E, T> where
E: Endpoint,
T: Clone + Send + Sync + 'static,
impl<E, T> Endpoint for AddDataEndpoint<E, T> where
E: Endpoint,
T: Clone + Send + Sync + 'static,
sourceimpl<E: Endpoint> Endpoint for CookieSessionEndpoint<E>
This is supported on crate feature session
only.
impl<E: Endpoint> Endpoint for CookieSessionEndpoint<E>
This is supported on crate feature
session
only.sourceimpl<T, E> Endpoint for OpenTelemetryTracingEndpoint<T, E> where
T: Tracer + Send + Sync,
E: Endpoint,
impl<T, E> Endpoint for OpenTelemetryTracingEndpoint<T, E> where
T: Tracer + Send + Sync,
E: Endpoint,
sourceimpl<T, E> Endpoint for ServerSessionEndpoint<T, E> where
T: SessionStorage,
E: Endpoint,
This is supported on crate feature session
only.
impl<T, E> Endpoint for ServerSessionEndpoint<T, E> where
T: SessionStorage,
E: Endpoint,
This is supported on crate feature
session
only.