Skip to main content

NestMiddleware

Trait NestMiddleware 

Source
pub trait NestMiddleware:
    Send
    + Sync
    + 'static {
    // Required method
    fn handle(&self, req: Request<Body>, next: NextFn) -> NextFuture;
}
Expand description

Trait for defining custom middleware.

Middleware sits between the incoming request and the NestForge pipeline (guards/interceptors/handlers). It can modify the request, response, or short-circuit the execution.

§Example

struct LoggerMiddleware;
impl NestMiddleware for LoggerMiddleware {
    fn handle(&self, req: Request<Body>, next: NextFn) -> NextFuture {
        Box::pin(async move {
            println!("Request: {:?}", req.uri());
            next(req).await
        })
    }
}

Required Methods§

Source

fn handle(&self, req: Request<Body>, next: NextFn) -> NextFuture

Implementors§