Trait poem::EndpointExt[][src]

pub trait EndpointExt: Endpoint {
    fn with<T>(self, middleware: T) -> T::Output
    where
        T: Middleware<Self>,
        Self: Sized
, { ... }
fn or<T>(self, other: T) -> Or<Self, T>
    where
        T: Endpoint,
        Self: Sized
, { ... }
fn before<F, Fut>(self, f: F) -> Before<Self, F>
    where
        F: Fn(Request) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Request> + Send + 'static,
        Self: Sized
, { ... }
fn after<F, Fut, R>(self, f: F) -> After<Self, F>
    where
        F: Fn(Self::Output) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = R> + Send + 'static,
        R: IntoResponse,
        Self: Sized
, { ... }
fn map_to_response(self) -> MapToResponse<Self>
    where
        Self: Sized
, { ... }
fn map_to_result(self) -> MapToResult<Self>
    where
        Self: Sized
, { ... }
fn and_then<F, Fut, R, R2>(self, f: F) -> AndThen<Self, F>
    where
        F: Fn(R) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<R2>> + Send + 'static,
        R: IntoResponse,
        R2: IntoResponse,
        Self: Endpoint<Output = Result<R>> + Sized
, { ... }
fn map_ok<F, Fut, R, R2>(self, f: F) -> MapOk<Self, F>
    where
        F: Fn(R) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = R2> + Send + 'static,
        R: IntoResponse,
        R2: IntoResponse,
        Self: Endpoint<Output = Result<R>> + Sized
, { ... }
fn map_err<F, Fut, R>(self, f: F) -> MapErr<Self, F>
    where
        F: Fn(Error) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Error> + Send + 'static,
        R: IntoResponse,
        Self: Endpoint<Output = Result<R>> + Sized
, { ... }
fn guard<T>(self, guard: T) -> GuardEndpoint<Self, T>
    where
        T: Guard,
        Self: Sized
, { ... } }
Expand description

Extension trait for Endpoint.

Provided methods

Use middleware to transform this endpoint.

Example

use poem::{handler, middleware::AddData, route, web::Data, EndpointExt};

#[handler]
async fn index(Data(data): Data<&i32>) -> String {
    format!("{}", data)
}

let app = route().at("/", index).with(AddData::new(100i32));

Composes a new endpoint of either this or the other endpoint.

Maps the request of this endpoint.

Example

use poem::{handler, http::StatusCode, Endpoint, EndpointExt, Error, Request, Result};

#[handler]
async fn index(data: String) -> String {
    data
}

let mut resp = index
    .before(|mut req| async move {
        req.set_body("abc");
        req
    })
    .call(Request::default())
    .await;
assert_eq!(resp.take_body().into_string().await.unwrap(), "abc");

Maps the output of this endpoint.

Example

use poem::{handler, http::StatusCode, Endpoint, EndpointExt, Error, Request, Result};

#[handler]
async fn index() -> &'static str {
    "abc"
}

let mut resp = index
    .after(|mut resp| async move {
        resp.take_body().into_string().await.unwrap() + "def"
    })
    .call(Request::default())
    .await;
assert_eq!(resp, "abcdef");

Convert the output of this endpoint into a response. Response.

Convert the output of this endpoint into a result Result<Response>. Response.

Calls f if the result is Ok, otherwise returns the Err value of self.

Maps the response of this endpoint.

Maps the error of this endpoint.

Add guard to the endpoint.

Implementors