Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1.52 KB

README.md

File metadata and controls

37 lines (27 loc) · 1.52 KB

@malijs/requestid

Mali request ID metadata middleware sources request ID into context

npm version build status

API

@malijs/requestid

Mali request ID metadata middleware. If the call has metadata with the request ID (or specified property) sets it into the context into target property. If request ID is not present creates one using UUID and sets it into metadata and context.

Param Type Description
options Options
options.name String Optional name of the metadata object property. Default: 'requestId'
options.target String | Boolean Optional name of the ctx property to set request id into. If not provided it is equal to options.name.
options.generator function Synchronous function to generate the request id if not present. Has to return a string. Default: uuid library.

Example

const rid = require('@malijs/requestid')

app.use(rid())
app.use('myFn', async (ctx, next) => {
  console.log(ctx.requestId) // request ID from metadata
  await next()
})

License

Apache-2.0