hono-middleware

Compose reusable middleware for Hono web applications with an onion-style execution model.

Updated Feb 7, 2026
One-click install
npx skills add https://github.com/olavocarvalho/engrain --skill hono-middleware-olavocarvalho
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hono-middleware
Source: https://github.com/olavocarvalho/engrain/tree/main/.agents/skills/hono-middleware
Command: npx skills add https://github.com/olavocarvalho/engrain --skill hono-middleware-olavocarvalho

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Hono-based applications benefit from modular, reusable middleware to manage cross-cutting concerns such as authentication, logging, CORS, and security, enabling clean separation of concerns.

Core Features & Use Cases

  • Onion-style execution model enabling pre- and post-route processing
  • 25+ built-in middleware for common needs (CORS, logging, auth, compression, etc.)
  • Type-safe creation and reuse of middleware across routes
  • Context variables and easy composition with app.use()
  • Best practices for middleware order and error handling, with real-world use cases
  • Use Case: Build an API with consistent security headers, logging, and rate limiting

Quick Start

Import middleware from hono/middleware, apply with app.use(), and chain multiple middleware for your routes.

Frequently Asked Questions about hono-middleware

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does the onion model work for Hono middleware composition?

The onion model in Hono middleware enables pre- and post-route processing by wrapping route handlers, allowing requests to pass inward through layers and responses to flow outward for tasks like logging and header modification.

How do I add authentication and CORS to a Hono API route?

To add authentication and CORS to a Hono API, import the built-in middleware modules and apply them using app.use() before your route handlers, enabling composable and type-safe cross-cutting concerns.

Can I reuse custom Hono middleware across multiple routes?

Yes, you can create type-safe custom middleware and reuse it across multiple routes by applying it globally with app.use() or attaching it to specific route handlers for consistent execution.

What is the best way to handle errors and rate limiting in Hono web apps?

The best way to handle errors and rate limiting in Hono is through composable middleware, applying built-in modules via app.use() to ensure consistent security and robust error handling across routes.

Does Hono support built-in middleware for logging and compression?

Yes, Hono supports 25+ built-in middleware for common needs including logging, compression, authentication, and CORS, which can be easily chained together using app.use() for route handlers.