HTTP Method Handlers
Hono provides method-specific handlers for defining routes. Each handler corresponds to an HTTP method:src/router.ts:17:
Method Chaining
You can chain multiple handlers on the same path:Handlers Without a Path
You can define handlers without specifying a path. The path from the previous call will be used:All Methods Handler
Theall() method matches any HTTP method:
Custom Methods with on()
For custom HTTP methods or multiple methods at once, use on():
src/hono-base.ts:144 shows how on() works:
Route Order and Matching
Routes are matched in the order they are defined. However, the specific router implementation determines the exact matching behavior:The default router uses a smart matching algorithm that prioritizes more specific routes over wildcards.
Wildcard Routes
Use* to match any path segment:
src/router/reg-exp-router/router.ts:149, wildcards are handled specially:
Pattern Matching
Hono supports various path patterns:Multiple Handlers
You can register multiple handlers for the same route by calling the method multiple times:src/hono-base.ts:130 shows this pattern:
Strict Mode
By default, Hono uses strict mode which distinguishes between paths with and without trailing slashes:src/hono-base.ts:172, the strict option affects the path matching: