2.0.0 • Published 1 year ago
koa-better-request-id v2.0.0
koa-better-request-id
If express-request-id and x-request-id have a baby ❤️.
Generates a unique Request ID for every incoming HTTP request. This unique ID is then passed to your application as an HTTP header called 'X-Request-Id'.
Support Node.js 18+.
Installation
# npm ..
$ npm install koa-better-request-id
# yarn ..
$ yarn add koa-better-request-idUsage
This is a practical example of how to use.
const Koa = require('koa');
const xRequestId = require ('koa-better-request-id');
const app = new Koa();
// You can pass options object to xRequestId
app.use(xRequestId());OPTIONS
You can pass an object that contains these keys to the xRequestId middleware:
uuidVersion— (String) Pick which version of UUID that should used.default to 'v4'uuidOpts— (Object) Optional UUID state to apply.default to {}uuidBuffer— (Array|buffer) Where UUID bytes are to be written.defaultto undefineduuidOffset— (Number) Starting index in buffer at which to begin writing.default to 0noHyphen— (Boolean) Abandon the hyphen or not.default to falsesetHeader— (Boolean) Should be added to response or not.default to trueheaderName— (String) Header name to use.default to 'X-Request-Id'attributeName— (String) Attribute name used for the identifier on the ctx/request objectdefault to 'id'