/Knowledge/sources/honojs__hono/llms-full/factory-helper-createmiddleware--6ffff05cf098.md
Factory Helper: createMiddleware() - hono-docs
Factory Helper: createMiddleware() Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://hono.dev/llms full.txt createmiddleware Su...
Factory Helper: createMiddleware()
Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://hono.dev/llms-full.txt#createmiddleware
Summary
createMiddleware() is shortcut of factory.createMiddleware(). This function will create your custom middleware. ```ts const messageMiddleware = createMiddleware(async (c, next) => { await next() c.res.headers.set('X-Message', 'Good m...
Content
createMiddleware() is shortcut of factory.createMiddleware().
This function will create your custom middleware.
const messageMiddleware = createMiddleware(async (c, next) => {
await next()
c.res.headers.set('X-Message', 'Good morning!')
})
Tip: If you want to get an argument like message, you can create it as a function like the following.
const messageMiddleware = (message: string) => {
return createMiddleware(async (c, next) => {
await next()
c.res.headers.set('X-Message', message)
})
}
app.use(messageMiddleware('Good evening!'))
Metadata
{
"chunk_index": 0,
"citation": "https://hono.dev/llms-full.txt#createmiddleware",
"coverage_role": "overview",
"qualified_title": "Hono / llms-full / Factory Helper > `createMiddleware()`",
"retrieved_at": "2026-07-02T05:51:01Z",
"section_index": 660,
"source_id": "/honojs/hono",
"source_type": "llms_full",
"target_label": "llms-full",
"title": "Factory Helper: createMiddleware()",
"upstream_url": "https://hono.dev/llms-full.txt",
"version": "2026"
}