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