Environment type extending base Env interface
Create a new WorkerRouter
Router name (default: 'unnamed')
Additional arguments passed to itty-router
Router name for logging
Logger instance
Underlying itty-router instance
Register middleware for all HTTP methods
Route path pattern (e.g., '/api/*')
Middleware function
This router instance for chaining
Register middleware for GET requests
Route path pattern
Middleware function
This router instance for chaining
Register a class-based route handler for all HTTP methods
Automatically registers GET, POST, PUT, DELETE, and PATCH methods from the handler class.
Route path pattern (e.g., '/users/:id')
RouteHandler class to instantiate
This router instance for chaining
Build the router and add 404 handler
Must be called before using the router in a Worker's fetch handler.
The underlying itty-router instance
Router for Cloudflare Workers with class-based handlers and automatic error handling
Example