Function poem::fn_endpoint[][src]

pub fn fn_endpoint<F, R>(f: F) -> impl Endpoint<Output = R> where
    F: Fn(Request) -> R + Send + Sync + 'static,
    R: IntoResponse
Expand description

Create an endpoint with a function.

Example

use poem::{fn_endpoint, http::Method, Endpoint, Request};

let ep = fn_endpoint(|req| req.method().to_string());

let resp = ep
    .call(Request::builder().method(Method::GET).finish())
    .await;
assert_eq!(resp, "GET");