0.2.0 • Published 5 years ago

@malijs/requestid v0.2.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

@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.

ParamTypeDescription
optionsOptions
options.nameStringOptional name of the metadata object property. Default: 'requestId'
options.targetString | BooleanOptional name of the ctx property to set request id into. If not provided it is equal to options.name.
options.generatorfunctionSynchronous 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