Module handler

Module handler 

Source
Expand description

HTTP request handler module

This module provides traits and utilities for handling HTTP requests. It defines the core abstraction for request processing through the Handler trait and provides utilities for creating handlers from async functions.

§Examples

use micro_http::handler::{Handler, make_handler};
use micro_http::protocol::body::ReqBody;
use http::{Request, Response};
use std::error::Error;

// Define an async handler function
async fn hello_handler(req: Request<ReqBody>) -> Result<Response<String>, Box<dyn Error + Send + Sync>> {
    Ok(Response::new("Hello World!".to_string()))
}

// Create a handler from the function
let handler = make_handler(hello_handler);

Structs§

HandlerFn
A wrapper type for function-based handlers

Traits§

Handler
A trait for handling HTTP requests

Functions§

make_handler
Creates a new handler from an async function