Koa Middleware Chain
A guide to building elegant APIs using Koa's onion-model middleware cascade with async/await.
Usage
Ask about Koa middleware patterns, context manipulation, error handling, or API composition.
Examples
- "Create a logging middleware that captures response time"
- "How does Koa's onion model differ from Express?"
- "Build error handling middleware with Koa"
Guidelines
- Always await next() to ensure downstream middleware executes
- Use ctx.state for passing data between middleware
- Handle errors with try/catch around await next()
- Keep the middleware chain order meaningful
- Use koa-compose for grouping related middleware