fastify-request-id

1.0.1 • Public • Published

Fastify Request Id JavaScript Style Guide

An alternative request id plugin for fastify

Install

> npm install --save fastify-request-id

Usage

const Fastify = require('fastify')
const requestId = require('fastify-request-id')

const fastify = Fastify()

fastify.register(requestId())

fastify.get('/', (request, reply) => {
  console.log(request.reqId) // osUlY5xlcT
  reply.send({ hello: 'world' })
  // Response headers =>  x-request-id: osUlY5xlcT
})

API

requestId([, pluginOpts])

  • getId (Function) - a custum funtion that return string (id). Default - random nano id with 10 charters
  • isAddToResponse (Boolean) - add response header with request id. Default - true
  • headerName (String) - if isAddToResponse is set to true, you can choose what will be the header name. Default - x-request-id

Readme

Keywords

Package Sidebar

Install

npm i fastify-request-id

Weekly Downloads

54

Version

1.0.1

License

Apache-2.0

Unpacked Size

13.9 kB

Total Files

6

Last publish

Collaborators

  • amitosdev