Request ID middleware for Hono
npm install hono-request-idThis middleware adds a unique requestId to each Hono request object. It uses hyperid to generate highly performant, sequential, and unique IDs by default.
``plain`
npm i hono hono-request-id
Default:
`ts
import { Hono } from "hono"
import { requestId } from "hono-request-id"
const app = new Hono()
app.use('*', requestId())
export default app
`
Custom:
`ts
import { Hono } from "hono"
import { requestId } from "hono-request-id"
import crypto from "node:crypto"
const app = new Hono()
app.use('*', requestId(crypto.randomUUID))
export default app
`
With Pino logger middleware:
`ts
import { Hono } from "hono"
import { requestId } from "hono-request-id"
import { pinoLogger } from "hono-pino-logger"
const app = new Hono()
app.use('*', requestId())
app.use('*', pinoLogger())
export default app
``
- Maksym Herasymov -
MIT