Skip to main content
Module

x/hono/hono-base.ts>HonoBase

Web Framework built on Web Standards
Extremely Popular
Go to Latest
class HonoBase
import { HonoBase } from "https://deno.land/x/hono@v4.2.7/hono-base.ts";

Constructors

new
HonoBase(options?: HonoOptions<E>)

Type Parameters

optional
E extends Env = Env
optional
S extends Schema = { }
optional
BasePath extends string = "/"

Properties

private
_basePath: string
private
errorHandler: ErrorHandler
private
notFoundHandler: NotFoundHandler
fetch: (
request: Request,
Env?: E["Bindings"] | { },
executionCtx?: ExecutionContext,
) => unknown

.fetch() will be entry point of your app.

fire: () => unknown

.fire() automatically adds a global fetch event listener. This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.

readonly
getPath: GetPath<E>
notFound: (handler: NotFoundHandler<E>) => unknown

.notFound() allows you to customize a Not Found Response.

app.notFound((c) => {
  return c.text('Custom 404 Message', 404)
})
onError: (handler: ErrorHandler<E>) => unknown

.onError() handles an error and returns a customized Response.

app.onError((err, c) => {
  console.error(`${err}`)
  return c.text('Custom Error Message', 500)
})
request: (
input: RequestInfo | URL,
requestInit?: RequestInit,
Env?: E["Bindings"] | { },
executionCtx?: ExecutionContext,
) => unknown

.request() is a useful method for testing. You can pass a URL or pathname to send a GET request. app will return a Response object.

test('GET /hello is ok', async () => {
  const res = await app.request('/hello')
  expect(res.status).toBe(200)
})
router: Router<[H, RouterRoute]>
routes: RouterRoute[]

Methods

private
addRoute(
method: string,
path: string,
handler: H,
)
private
clone(): Hono<E, S, BasePath>
private
dispatch(
request: Request,
executionCtx: ExecutionContext | FetchEventLike | undefined,
env: E["Bindings"],
method: string,
): Response | Promise<Response>
private
handleError(err: unknown, c: Context<E>)
private
matchRoute(method: string, path: string)
basePath<SubPath extends string>(path: SubPath): Hono<E, S, MergePath<BasePath, SubPath>>

.basePath() allows base paths to be specified.

mount(
path: string,
applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>,
optionHandler?: (c: Context) => unknown,
): Hono<E, S, BasePath>
route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app?: Hono<SubEnv, SubSchema, SubBasePath>): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>