Overview
Middleware executes before endpoint handlers, providing authentication, context, and input validation. Middleware can be chained and composed.Configuration
input
Type:ZodObject
Input validation schema for the middleware.
handler
Type:Handler<Input, Output, Context>
Required: Yes
Async function that returns context for endpoints.
security
Type:SecuritySchema
Security requirements for OpenAPI documentation.
Handler Return Value
The middleware handler must return an object that becomes part of the endpoint’s context:Chaining Middleware
Security Declarations
Declare security requirements for documentation:Examples
Authentication Middleware
Rate Limiting Middleware
See Also
EndpointsFactory
Add middleware to factories
Authentication Guide
Complete authentication examples