Request Handling
BurgerAPI handles each request by running middleware (if any) and then the route handler. Middleware can short-circuit by returning a Response, or continue by returning undefined, or return a function to run after the handler (e.g. to modify the response).
Flow
- Global middleware runs first (in order).
- Route-specific middleware runs next (if the route defines any).
- Route handler runs (e.g.
GET,POSTexported fromroute.ts). - After-middleware (if a middleware returned a function) runs with the response.
Request object
Handlers and middleware receive a BurgerRequest object (extends the standard request with params, validated, etc.). Use it to read headers, URL, and validated query/body from Zod validation.
Key docs
- Middleware System — How middleware works.
- Global Middleware and Route-Specific Middleware.
- Validation — Validating params, query, and body with Zod.