hono · Hono Docs
Middleware
Teaches how to implement, order, and extend Hono middleware, including using the createMiddleware factory for type-safe context extension and modifying responses after the handler executes.
Derived skill
Files assembled from official documentation
Viewing SKILL.md
Middleware
Teaches how to implement, order, and extend Hono middleware, including using the createMiddleware factory for type-safe context extension and modifying responses after the handler executes.
When To Use
Use when you need to intercept requests, modify responses, extend the Hono context with custom variables, or implement reusable logic across multiple routes.
Reference Files
| File | Contains | Use For |
|---|---|---|
SKILL.md | Entry point: scope, routing table, and workflow. | Start here. |
docs/middleware-workflow-guide.md | A guide explaining the definition, execution order, built-in options, and custom implementation of middleware in Hono. | Questions about a guide explaining the definition, execution order, built-in options, and custom implementation of middleware in Hono. |
examples/middleware-hono-middleware-typescript-usage-examples.ts | TypeScript code demonstrating how to apply different middleware patterns to routes and methods in a Hono application. | Exact payloads, commands, or snippets shown in TypeScript code demonstrating how to apply different middleware patterns to routes and methods in a Hono application. |
examples/middleware-hono-middleware-typescript.ts | A TypeScript code example demonstrating how to implement and apply middleware within a Hono application. | Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to implement and apply middleware within a Hono application. |
examples/middleware-hono-middleware-logger-cors-basicauth-typescript.ts | A TypeScript example demonstrating the sequential application of logger, cors, and basicAuth middleware in a Hono application. | Exact payloads, commands, or snippets shown in A TypeScript example demonstrating the sequential application of logger, cors, and basicAuth middleware in a Hono app... |
examples/middleware-hono-middleware-async-execution-order.ts | A TypeScript example demonstrating how multiple asynchronous middleware functions execute in sequence using the next function in Hono. | Exact payloads, commands, or snippets shown in A TypeScript example demonstrating how multiple asynchronous middleware functions execute in sequence using the next... |
examples/middleware-hono-middleware-execution-order.text | A text representation demonstrating the sequential execution flow of multiple Hono middleware layers. | Exact payloads, commands, or snippets shown in A text representation demonstrating the sequential execution flow of multiple Hono middleware layers. |
examples/middleware-hono-middleware-typescript-usage-examples-2.ts | A TypeScript code example demonstrating how to apply built-in middleware like logger, poweredBy, and basicAuth to a Hono application instance. | Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to apply built-in middleware like logger, poweredBy, and basicAuth to a H... |
examples/middleware-hono-middleware-websocket-upgrade-typescript.ts | A TypeScript example demonstrating how to use the upgradeWebSocket middleware in a Hono application. | Exact payloads, commands, or snippets shown in A TypeScript example demonstrating how to use the upgradeWebSocket middleware in a Hono application. |
examples/middleware-hono-middleware-custom-logger-and-header-typescript.ts | A TypeScript example demonstrating how to implement custom middleware for logging requests and adding custom response headers in a Hono application. | Exact payloads, commands, or snippets shown in A TypeScript example demonstrating how to implement custom middleware for logging requests and adding custom response... |
examples/middleware-hono-middleware-factory-create-typescript.ts | A TypeScript example demonstrating how to use the createMiddleware factory function to build custom middleware in Hono. | Exact payloads, commands, or snippets shown in A TypeScript example demonstrating how to use the createMiddleware factory function to build custom middleware in Hono. |
examples/middleware-hono-middleware-create-middleware-typescript.ts | A TypeScript code example demonstrating how to use the createMiddleware function to define custom middleware in Hono. | Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to use the createMiddleware function to define custom middleware in Hono. |
examples/middleware-hono-middleware-create-middleware-typescript-2.ts | A TypeScript example demonstrating how to use the createMiddleware function to intercept and modify a response in Hono. | Exact payloads, commands, or snippets shown in A TypeScript example demonstrating how to use the createMiddleware function to intercept and modify a response in Hono. |
examples/middleware-hono-middleware-cors-typescript.ts | A TypeScript code example demonstrating how to implement CORS middleware in a Hono application. | Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to implement CORS middleware in a Hono application. |
examples/middleware-hono-middleware-factory-create-typescript-2.ts | A TypeScript example demonstrating how to use the createMiddleware factory function to define and apply custom middleware in a Hono application. | Exact payloads, commands, or snippets shown in A TypeScript example demonstrating how to use the createMiddleware factory function to define and apply custom middle... |
examples/middleware-hono-middleware-factory-create-typescript-3.ts | A TypeScript example demonstrating how to use the createMiddleware factory to define custom middleware with typed context variables in Hono. | Exact payloads, commands, or snippets shown in A TypeScript example demonstrating how to use the createMiddleware factory to define custom middleware with typed con... |
What This Skill Covers
- Middleware works before/after the endpoint Handler. We can get the Request before dispatching or manipulate the Response after dispatching.
- Main sections:
Definition of Middleware,Execution order,Built-in Middleware,Custom Middleware,Modify the Response After Next.
Workflow
- Open the most relevant file under
docs/for the exact documented workflow and wording. - Open
schemas/files for exact structured contracts. - Open
examples/files for concrete requests, commands, snippets, and manifests. - Do not add behavior or configuration that is not present in the attached source files.
Canonical source: https://hono.dev/docs/guides/middleware