1.0.1 • Published 2 years ago

fastify-reqid v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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.