Hono
TheHono class is the main entry point for creating Hono web applications. It extends HonoBase and provides routing, middleware, and request handling capabilities.
Constructor
Creates a new Hono application instance.HonoOptions<E>
Configuration options for the Hono instance
Type Parameters
Env
default:"BlankEnv"
Environment type that defines bindings and variables available in your app
Schema
default:"BlankSchema"
Schema type that defines your API routes for type-safe client generation
string
default:"'/'"
Base path prefix for all routes in this app instance
Example
Route Methods
Define HTTP route handlers for specific methods.get
Register a GET route handler.string
The route path. If omitted, handlers are applied to the current path.
Handler[]
required
One or more handler functions or middleware
Hono
Returns the Hono instance for method chaining
post
Register a POST route handler.put
Register a PUT route handler.delete
Register a DELETE route handler.patch
Register a PATCH route handler.options
Register an OPTIONS route handler.all
Register a route handler that matches all HTTP methods.Middleware Methods
use
Register middleware that runs for matching routes.string
Path pattern to match. Defaults to
'*' (all routes).MiddlewareHandler[]
required
One or more middleware functions
Hono
Returns the Hono instance for method chaining
on
Register a route handler for custom HTTP methods or multiple methods.string | string[]
required
HTTP method(s) to match
string | string[]
required
Path(s) to match
Handler[]
required
Route handlers
Hono
Returns the Hono instance for method chaining
Application Methods
route
Mount another Hono instance as a sub-application.string
required
Base path for the sub-application
Hono
required
The Hono instance to mount
Hono
Returns the Hono instance with merged routes
basePath
Create a new instance with a base path prefix.string
required
Base path prefix to add
Hono
Returns a new Hono instance with the base path applied
mount
Mount applications built with other frameworks.string
required
Base path for the mounted application
(request: Request, ...args: any) => Response | Promise<Response>
required
Request handler from another framework
MountOptions
Configuration for how the request should be handled
Hono
Returns the Hono instance for method chaining
Error Handling
onError
Register a custom error handler.ErrorHandler<E>
required
Function that receives an error and context, returns a Response
Hono
Returns the Hono instance for method chaining
notFound
Register a custom 404 handler.NotFoundHandler<E>
required
Function that receives a context and returns a Response
Hono
Returns the Hono instance for method chaining
Request Handling
fetch
The main entry point for handling requests.Request
required
The incoming Request object
E['Bindings']
Environment bindings (e.g., Cloudflare Workers bindings)
ExecutionContext
Execution context for async operations
Response | Promise<Response>
The response to send back to the client
request
Convenience method for testing that creates a Request and calls fetch.Request | string | URL
required
Request object, URL string, or pathname
RequestInit
Request initialization options
E['Bindings']
Environment bindings
ExecutionContext
Execution context
Response | Promise<Response>
The response from the application