/Knowledge/sources/honojs__hono/llms-full/middleware-context-access-inside-middleware-arguments-extending-the-context-in-middleware--78532942846c.md
Middleware: Context access inside Middleware arguments > Extending th...
Middleware: Context access inside Middleware arguments Extending the Context in Middleware Source evidence: /Sources/honojs hono/provenance.md Canonical cita...
Middleware: Context access inside Middleware arguments > Extending the Context in Middleware
Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://hono.dev/llms-full.txt#extending-the-context-in-middleware
Summary
To extend the context inside middleware, use c.set. You can make this type-safe by passing a { Variables: { yourVariable: YourVariableType } } generic argument to the createMiddleware function. ```ts import { createMiddleware } fro...
Content
To extend the context inside middleware, use c.set. You can make this type-safe by passing a { Variables: { yourVariable: YourVariableType } } generic argument to the createMiddleware function.
import { createMiddleware } from 'hono/factory'
const echoMiddleware = createMiddleware<{
Variables: {
echo: (str: string) => string
}
}>(async (c, next) => {
c.set('echo', (str) => str)
await next()
})
app.get('/echo', echoMiddleware, (c) => {
return c.text(c.var.echo('Hello!'))
})
Metadata
{
"chunk_index": 0,
"citation": "https://hono.dev/llms-full.txt#extending-the-context-in-middleware",
"coverage_role": "overview",
"qualified_title": "Hono / llms-full / Middleware > Context access inside Middleware arguments > Extending the Context in Middleware",
"retrieved_at": "2026-07-02T05:51:01Z",
"section_index": 118,
"source_id": "/honojs/hono",
"source_type": "llms_full",
"target_label": "llms-full",
"title": "Middleware: Context access inside Middleware arguments > Extending the Context in Middleware",
"upstream_url": "https://hono.dev/llms-full.txt",
"version": "2026"
}