Skip to main content
This release is 7 versions behind 4.7.7 — the latest version of @hono/hono. Jump to latest

@hono/hono@4.6.20
Built and signed on GitHub Actions

Web framework built on Web Standards

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
76%
Published
3 months ago (4.6.20)

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

class Context

Constructors

new
Context(
req: Request,
options?: ContextOptions<E>,
)

Creates an instance of the Context class.

Type Parameters

E extends Env = any
P extends string = any
I extends Input = { }

Properties

body: BodyRespond

.body() can return the HTTP response. You can set headers with .header() and set HTTP status code with .status. This can also be set in .text(), .json() and so on.

env: E["Bindings"]

.env can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.

error: Error | undefined

.error can get the error object from the middleware if the Handler throws an error.

readonly
event: FetchEventLike
get: Get<IsAny<E> extends true ? { Variables: ContextVariableMap & Record<string, any>; } : E>

.get() can use the value specified by the key.

getLayout: () => Layout<PropsForRenderer & { Layout: Layout; }> | undefined

Gets the current layout for the response.

header: SetHeaders

.header() can set headers.

html: HTMLRespond
json: JSONRespond

.json() can render JSON as Content-Type:application/json.

newResponse: NewResponse

.notFound() can return the Not Found Response.

redirect: <T extends RedirectStatusCode = 302>(
location: string | URL,
status?: T,
) => Response & TypedResponse<undefined, T, "redirect">

.redirect() can Redirect, default status code is 302.

render: Renderer

.render() can create a response within a layout.

writeonly
res: Response | undefined

Sets the Response object for the current request.

readonly
req: HonoRequest<P, I["out"]>

.req is the instance of HonoRequest.

readonly
res: Response
set: Set<IsAny<E> extends true ? { Variables: ContextVariableMap & Record<string, any>; } : E>

.set() can set the value specified by the key.

setLayout: (layout: Layout<PropsForRenderer & { Layout: Layout; }>) => Layout<PropsForRenderer & { Layout: Layout; }>

Sets the layout for the response.

setRenderer: (renderer: Renderer) => void

.setRenderer() can set the layout in the custom middleware.

status: (status: StatusCode) => void
text: TextRespond

.text() can render text as Content-Type:text/plain.

readonly
var: Readonly<ContextVariableMap & (IsAny<E["Variables"]> extends true ? Record<string, any> : E["Variables"])>

.var can access the value of a variable.

Add Package

deno add jsr:@hono/hono

Import symbol

import { Context } from "@hono/hono";

---- OR ----

Import directly with a jsr specifier

import { Context } from "jsr:@hono/hono";

Add Package

npx jsr add @hono/hono

Import symbol

import { Context } from "@hono/hono";

Add Package

yarn dlx jsr add @hono/hono

Import symbol

import { Context } from "@hono/hono";

Add Package

pnpm dlx jsr add @hono/hono

Import symbol

import { Context } from "@hono/hono";

Add Package

bunx jsr add @hono/hono

Import symbol

import { Context } from "@hono/hono";