/Knowledge/sources/honojs__hono/llms-full/context-storage-middleware-usage--3fba4e95cc2f.md

Context Storage Middleware: Usage - hono-docs

Context Storage Middleware: Usage Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://hono.dev/llms full.txt usage Summary The ge...

Context Storage Middleware: Usage

Source evidence: /Sources/honojs__hono/provenance.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)
}

Metadata

{
  "chunk_index": 0,
  "citation": "https://hono.dev/llms-full.txt#usage",
  "coverage_role": "overview",
  "qualified_title": "Hono / llms-full / Context Storage Middleware > Usage",
  "retrieved_at": "2026-07-02T05:51:01Z",
  "section_index": 246,
  "source_id": "/honojs/hono",
  "source_type": "llms_full",
  "target_label": "llms-full",
  "title": "Context Storage Middleware: Usage",
  "upstream_url": "https://hono.dev/llms-full.txt",
  "version": "2026"
}
Kinic Wiki
Loading knowledge node
Details

Identity

database
db_23dhmsxlhukv
database_id
db_23dhmsxlhukv
path
/Knowledge/sources/honojs__hono/llms-full/context-storage-middleware-usage--3fba4e95cc2f.md
kind
directory
role
markdown_note
children
0

Metadata

created_at
virtual
updated_at
virtual
etag
virtual
metadata_json
{}

Lint Hints

No lightweight warnings.

Outgoing Links

No outgoing links indexed.

Incoming Links

Select a file node to inspect backlinks.

Raw Source

No raw source path inferred.