pub fn make<F, Fut, T, R>(f: F) -> impl Endpoint<Output = T> where
F: Fn(Request) -> Fut + Send + Sync,
Fut: Future<Output = R> + Send,
T: IntoResponse + Sync,
R: IntoResult<T>,
Expand description
Create an endpoint with a asyncness function.
The output can be any type that implements IntoResult
.
Example
use poem::{endpoint::make, http::Method, Endpoint, Request};
let ep = make(|req| async move { req.method().to_string() });
let resp = ep
.call(Request::builder().method(Method::GET).finish())
.await
.unwrap();
assert_eq!(resp, "GET");