fastify-reqid
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

fastify-reqid

CI NPM version js-standard-style

A plugin for Fastify that adds support for request-id.

Supports Fastify versions 4.x.

Support TypeScript

Install

# npm
npm i fastify-reqid

# pnpm
pnpm add fastify-reqid

# yarn

yarn add fastify-reqid

Usage

const fastify = require('fastify')()

fastify.register(require('fastify-reqid'), {
  // put your options here
})

fastify.get('/', (req, reply) => {
  reply.send({ hello: 'world' })
})

fastify.listen(3000)

You can use it as is without passing any option or you can configure it as explained below.

Options

  • generateHash: Generate x-request-id hash. For example:
generateHash: () => {
  return uuidv4();
}
  • findRequestHeader: Find request id in header. If found, the hash in the request header is used first.

  • addResponseHeader: Add request id to header. If it is undefined, it will not be added.

License

Licensed under MIT.

Package Sidebar

Install

npm i fastify-reqid

Weekly Downloads

9

Version

1.0.1

License

MIT

Unpacked Size

5.63 kB

Total Files

5

Last publish

Collaborators

  • black_hole