Skip to main content

handler

Function handler 

Source
pub fn handler<S, F, Fut>(f: F) -> Handler<S>
where S: Send + Sync + 'static, F: Fn(Request<Incoming>, State<S>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Response<ResponseBody>, ServeError>> + Send + 'static,
Expand description

Wrap an async function to create a handler.

§Example

use mini_serve::handler;
use hyper::StatusCode;
use hyper::body::Bytes;

let h = handler(|req, state| async move {
    Ok::<_, mini_serve::ServeError>(
        mini_serve::json(StatusCode::OK, &serde_json::json!({"status": "ok"}))
    )
});