/Wiki/sources/honojs__hono/2026/https-hono-dev-llms-full-txt-set-get-ef7f4add7357-set-get-s0561-c0000.md
set() / get() - hono-docs
set() / get() Source evidence: /Sources/raw/honojs hono/honojs hono.md Canonical citation: https://hono.dev/llms full.txt set get Summary Get and set arbitra...
set() / get()
Source evidence: /Sources/raw/honojshono/honojshono.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.