Function poem::endpoint::make

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

let ep = make(|req| async move { req.method().to_string() });
let app = TestClient::new(ep);

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