Trait poem::endpoint::Endpoint [−][src]
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
type Output = R2
type Output = R2
type Output = T
type Output = T
impl<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.impl<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.