Expand description
Middleware trait and types
Middleware allows you to add cross-cutting functionality to your application, such as logging, authentication, or request/response modification.
§Examples
use ruffus::{Middleware, Request, Response, Next};
use async_trait::async_trait;
struct Logger;
#[async_trait]
impl Middleware for Logger {
async fn handle(&self, req: Request, next: Next) -> ruffus::Result<Response> {
println!("{} {}", req.method(), req.uri());
next.run(req).await
}
}Structs§
- Next
- Represents the next middleware or handler in the chain.
Traits§
- Handler
- Trait for request handlers.
- Middleware
- Trait for middleware that can process requests.
Functions§
- execute_
middleware_ stack - Executes a middleware stack with a final handler.
Type Aliases§
- Boxed
Handler - Type alias for boxed handler functions.