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.

Required Associated Types

Represents the response of the endpoint.

Required Methods

Get the response to the request.

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, test::TestClient, Endpoint, Request,
    Result,
};

#[handler]
fn index() -> Result<()> {
    Err(NotFoundError.into())
}

TestClient::new(index)
    .get("/")
    .send()
    .await
    .assert_status(StatusCode::NOT_FOUND);

Implementations on Foreign Types

Implementors