logo
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

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, 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