pub trait Endpoint: Send + Sync {
type Output: IntoResponse;
// Required method
fn call(
&self,
req: Request
) -> impl Future<Output = Result<Self::Output>> + Send;
// Provided method
fn get_response(
&self,
req: Request
) -> impl Future<Output = Response> + Send { ... }
}
Expand description
An HTTP request handler.
Required Associated Types§
sourcetype Output: IntoResponse
type Output: IntoResponse
Represents the response of the endpoint.
Required Methods§
Provided Methods§
sourcefn get_response(&self, req: Request) -> impl Future<Output = Response> + Send
fn get_response(&self, req: Request) -> impl Future<Output = Response> + Send
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, test::TestClient, Endpoint, Request,
Result,
};
#[handler]
fn index() -> Result<()> {
Err(NotFoundError.into())
}
TestClient::new(index)
.get("/")
.send()
.await
.assert_status(StatusCode::NOT_FOUND);
Object Safety§
This trait is not object safe.
Implementations on Foreign Types§
Implementors§
source§impl Endpoint for Http01Endpoint
Available on crate features acme-base
and server
only.
impl Endpoint for Http01Endpoint
Available on crate features
acme-base
and server
only.source§impl<E, F> Endpoint for InspectAllError<E, F>
impl<E, F> Endpoint for InspectAllError<E, F>
source§impl<E, F, ErrType> Endpoint for InspectError<E, F, ErrType>
impl<E, F, ErrType> Endpoint for InspectError<E, F, ErrType>
source§impl<E, F, Fut, R> Endpoint for CatchAllError<E, F, R>
impl<E, F, Fut, R> Endpoint for CatchAllError<E, F, R>
source§impl<E, F, Fut, R, ErrType> Endpoint for CatchError<E, F, R, ErrType>
impl<E, F, Fut, R, ErrType> Endpoint for CatchError<E, F, R, ErrType>
source§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,
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,
source§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,
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,
source§impl<E, T> Endpoint for AddDataEndpoint<E, T>
impl<E, T> Endpoint for AddDataEndpoint<E, T>
source§impl<E: Endpoint> Endpoint for NormalizePathEndpoint<E>
impl<E: Endpoint> Endpoint for NormalizePathEndpoint<E>
source§impl<E: Endpoint> Endpoint for CookieSessionEndpoint<E>
Available on crate feature session
only.
impl<E: Endpoint> Endpoint for CookieSessionEndpoint<E>
Available on crate feature
session
only.source§impl<E: Endpoint, H: PanicHandler> Endpoint for CatchPanicEndpoint<E, H>
impl<E: Endpoint, H: PanicHandler> Endpoint for CatchPanicEndpoint<E, H>
source§impl<T> Endpoint for dyn DynEndpoint<Output = T> + '_where
T: IntoResponse,
impl<T> Endpoint for dyn DynEndpoint<Output = T> + '_where
T: IntoResponse,
source§impl<T, E> Endpoint for OpenTelemetryTracingEndpoint<T, E>
impl<T, E> Endpoint for OpenTelemetryTracingEndpoint<T, E>
source§impl<T, E> Endpoint for ServerSessionEndpoint<T, E>where
T: SessionStorage,
E: Endpoint,
Available on crate feature session
only.
impl<T, E> Endpoint for ServerSessionEndpoint<T, E>where
T: SessionStorage,
E: Endpoint,
Available on crate feature
session
only.