Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno_nest/modules/hono/mod.ts>HonoContext

Refer to nestjs to realize some common functions for Deno, support hono and oak
Latest
class HonoContext
import { HonoContext } from "https://deno.land/x/deno_nest@v3.15.1/modules/hono/mod.ts";

Constructors

new
HonoContext(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; }>) => Layout<PropsForRenderer & { Layout: Layout; }>
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.