/Knowledge/sources/honojs__hono/llms-full/context-set-get--2913739ea801.md
Context: set() / get() - hono-docs
Context: set() / get() Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://hono.dev/llms full.txt set get Summary Get and set arb...
Context: set() / get()
Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://hono.dev/llms-full.txt#set-get
Summary
Get and set arbitrary key-value pairs, with a lifetime of the current request. This allows passing specific values between middleware or from middleware to route handlers. ```ts twoslash import { Hono } from 'hono' const app = new Hono (...
Content
Get and set arbitrary key-value pairs, with a lifetime of the current request. This allows passing specific values between middleware or from middleware to route handlers.
import { Hono } from 'hono'
const app = new Hono<{ Variables: { message: string } }>()
// ---cut---
app.use(async (c, next) => {
c.set('message', 'Hono is cool!!')
await next()
})
app.get('/', (c) => {
const message = c.get('message')
return c.text(`The message is "${message}"`)
})
Pass the Variables as Generics to the constructor of Hono to make it type-safe.
import { Hono } from 'hono'
// ---cut---
type Variables = {
message: string
}
const app = new Hono<{ Variables: Variables }>()
The value of c.set / c.get are retained only within the same request. They cannot be shared or persisted across different requests.
Metadata
{
"chunk_index": 0,
"citation": "https://hono.dev/llms-full.txt#set-get",
"coverage_role": "overview",
"qualified_title": "Hono / llms-full / Context > set() / get()",
"retrieved_at": "2026-07-02T05:51:01Z",
"section_index": 561,
"source_id": "/honojs/hono",
"source_type": "llms_full",
"target_label": "llms-full",
"title": "Context: set() / get()",
"upstream_url": "https://hono.dev/llms-full.txt",
"version": "2026"
}