Getting Started
Core Concepts
Built-In Middleware
Advanced Features
Troubleshooting
Basic routing in Hono allows you to map incoming HTTP requests to specific handler functions. By defining paths and HTTP methods, you control how your application responds to different traffic directed at your server.
Hono uses a Hono instance to manage these mappings, providing a simple, chainable API for defining routes.
To create basic routes, instantiate the Hono class and use the method names corresponding to the HTTP verbs (e.g., get, post, put, delete).
Hono:
import { Hono } from 'hono'const app = new Hono()app.get('/hello', (c) => c.text('Hello!'))You can define routes for standard HTTP methods. Every method follows the same signature: app.method(path, handler).
Tip
Use app.all(path, handler) if you need a single handler to respond to all HTTP methods for a specific path.
When building larger applications, you can organize your routes using .basePath() or .route().
This method prefixes all routes defined on that instance with the provided path.
const api = new Hono().basePath('/api')
api.get('/users', (c) => c.json({ users: [] })) // GET /api/usersYou can nest another Hono instance under a specific path, effectively modularizing your codebase.
const app = new Hono()
const userApp = new Hono()
userApp.get('/', (c) => c.text('List of users'))
app.route('/users', userApp) // GET /users/You can customize how Hono handles paths during instantiation.
const app = new Hono({
strict: false // If false, /hello/ matches /hello
})Warning
By default, strict is set to true. This means that a route defined as /hello will not match /hello/ (a trailing slash). Ensure your client requests match your defined path strictness.
Note
Hono automatically uses a SmartRouter by default, which switches between high-performance strategies (like Trie or RegExp) to ensure your routes are matched as quickly as possible. You do not need to configure this manually unless you have specific routing requirements.