/Wiki/sources/honojs__hono/2026/https-hono-dev-llms-full-txt-usage-492647be7ffd-usage-s0246-c0000.md
Usage - hono-docs
Usage Source evidence: /Sources/raw/honojs hono/honojs hono.md Canonical citation: https://hono.dev/llms full.txt usage Summary The getContext() will return...
Usage
Source evidence: /Sources/raw/honojshono/honojshono.md Canonical citation: https://hono.dev/llms-full.txt#usage
Summary
The getContext() will return the current Context object if the contextStorage() is applied as a middleware. ```ts type Env = { Variables: { message: string } } const app = new Hono () app.use(contextStorage()) app.use(async (c, next)...
Content
The getContext() will return the current Context object if the contextStorage() is applied as a middleware.
type Env = {
Variables: {
message: string
}
}
const app = new Hono<Env>()
app.use(contextStorage())
app.use(async (c, next) => {
c.set('message', 'Hello!')
await next()
})
// You can access the variable outside the handler.
const getMessage = () => {
return getContext<Env>().var.message
}
app.get('/', (c) => {
return c.text(getMessage())
})On Cloudflare Workers, you can access the bindings outside the handler.
type Env = {
Bindings: {
KV: KVNamespace
}
}
const app = new Hono<Env>()
app.use(contextStorage())
const setKV = (value: string) => {
return getContext<Env>().env.KV.put('key', value)
}