Skip to main content
Module

x/hono/mod.ts>Context

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

Constructors

new
Context(req: HonoRequest<P, I["out"]>, options?: ContextOptions<E>)

Type Parameters

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

Properties

private
_var: E["Variables"]
private
layout: Layout<PropsForRenderer & { Layout: Layout; }> | undefined
private
notFoundHandler: NotFoundHandler<E>
private
renderer: Renderer
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
readonly
executionCtx: ExecutionContext
finalized: boolean
get: Get<E>

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

getLayout: () => unknown
header: (
name: string,
value: string | undefined,
options?: { append?: boolean; },
) => void

.header() can set headers.

html: HTMLRespond
json: JSONRespond

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

newResponse: NewResponse
notFound: () => Response | Promise<Response>

.notFound() can return the Not Found Response.

redirect: (location: string, status?: RedirectStatusCode) => Response

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

render: Renderer

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

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

.req is the instance of HonoRequest.

set: Set<E>

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

setLayout: (layout: Layout<PropsForRenderer & { Layout: Layout; }>) => unknown
setRenderer: (renderer: Renderer) => unknown

.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.