@malijs/requestid

0.2.0 • Public • Published

@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

Package Sidebar

Install

npm i @malijs/requestid

Weekly Downloads

123

Version

0.2.0

License

Apache-2.0

Unpacked Size

16 kB

Total Files

5

Last publish

Collaborators

  • anonrig
  • bojand