Function poem::endpoint::make_sync

source ·
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, test::TestClient, Endpoint, Request};

let ep = make_sync(|req| req.method().to_string());
let cli = TestClient::new(ep);

let resp = cli.get("/").send().await;
resp.assert_status_is_ok();
resp.assert_text("GET").await;