Trait poem::endpoint::Endpoint

source ·
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§

source

type Output: IntoResponse

Represents the response of the endpoint.

Required Methods§

source

fn call( &self, req: Request ) -> impl Future<Output = Result<Self::Output>> + Send

Get the response to the request.

Provided Methods§

source

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§

source§

impl<T: Endpoint + ?Sized> Endpoint for &T

§

type Output = <T as Endpoint>::Output

source§

async fn call(&self, req: Request) -> Result<Self::Output>

source§

impl<T: Endpoint + ?Sized> Endpoint for Box<T>

§

type Output = <T as Endpoint>::Output

source§

async fn call(&self, req: Request) -> Result<Self::Output>

source§

impl<T: Endpoint + ?Sized> Endpoint for Arc<T>

§

type Output = <T as Endpoint>::Output

source§

async fn call(&self, req: Request) -> Result<Self::Output>

Implementors§

source§

impl Endpoint for Http01Endpoint

Available on crate features acme-base and server only.
source§

impl Endpoint for Route

source§

impl Endpoint for RouteDomain

source§

impl Endpoint for RouteMethod

source§

impl Endpoint for RouteScheme

source§

impl Endpoint for StaticFileEndpoint

source§

impl Endpoint for StaticFilesEndpoint

source§

impl<E, F> Endpoint for InspectAllError<E, F>
where E: Endpoint, F: Fn(&Error) + Send + Sync,

§

type Output = <E as Endpoint>::Output

source§

impl<E, F, ErrType> Endpoint for InspectError<E, F, ErrType>
where E: Endpoint, F: Fn(&ErrType) + Send + Sync, ErrType: Error + Send + Sync + 'static,

§

type Output = <E as Endpoint>::Output

source§

impl<E, F, Fut> Endpoint for Before<E, F>
where E: Endpoint, F: Fn(Request) -> Fut + Send + Sync, Fut: Future<Output = Result<Request>> + Send,

§

type Output = <E as Endpoint>::Output

source§

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,

source§

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,

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,

§

type Output = R2

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,

§

type Output = R2

source§

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

source§

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

source§

impl<E, T> Endpoint for AddDataEndpoint<E, T>
where E: Endpoint, T: Clone + Send + Sync + 'static,

§

type Output = <E as Endpoint>::Output

source§

impl<E: RustEmbed + Send + Sync> Endpoint for EmbeddedFileEndpoint<E>

source§

impl<E: RustEmbed + Send + Sync> Endpoint for EmbeddedFilesEndpoint<E>

source§

impl<E: Endpoint> Endpoint for CompressionEndpoint<E>

source§

impl<E: Endpoint> Endpoint for CookieJarManagerEndpoint<E>

source§

impl<E: Endpoint> Endpoint for CorsEndpoint<E>

source§

impl<E: Endpoint> Endpoint for CsrfEndpoint<E>

§

type Output = <E as Endpoint>::Output

source§

impl<E: Endpoint> Endpoint for NormalizePathEndpoint<E>

§

type Output = <E as Endpoint>::Output

source§

impl<E: Endpoint> Endpoint for OpenTelemetryMetricsEndpoint<E>

source§

impl<E: Endpoint> Endpoint for PropagateHeaderEndpoint<E>

source§

impl<E: Endpoint> Endpoint for SensitiveHeaderEndpoint<E>

source§

impl<E: Endpoint> Endpoint for SetHeaderEndpoint<E>

source§

impl<E: Endpoint> Endpoint for SizeLimitEndpoint<E>

§

type Output = <E as Endpoint>::Output

source§

impl<E: Endpoint> Endpoint for TokioMetricsEndpoint<E>

source§

impl<E: Endpoint> Endpoint for TracingEndpoint<E>

source§

impl<E: Endpoint> Endpoint for CookieSessionEndpoint<E>

Available on crate feature session only.
§

type Output = <E as Endpoint>::Output

source§

impl<E: Endpoint> Endpoint for MapToResponse<E>

source§

impl<E: Endpoint> Endpoint for ToResponse<E>

source§

impl<E: Endpoint, H: PanicHandler> Endpoint for CatchPanicEndpoint<E, H>

source§

impl<T> Endpoint for dyn DynEndpoint<Output = T> + '_
where T: IntoResponse,

§

type Output = T

source§

impl<T, E> Endpoint for OpenTelemetryTracingEndpoint<T, E>
where T: Tracer + Send + Sync, T::Span: Send + Sync + 'static, E: Endpoint,

source§

impl<T, E> Endpoint for ServerSessionEndpoint<T, E>
where T: SessionStorage, E: Endpoint,

Available on crate feature session only.
§

type Output = <E as Endpoint>::Output