Socket
Socket
Sign inDemoInstall

request-id

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    request-id

Allows you to identify client requests within non-sequential logs such as Syslog by adding a response header of `X-Request-Id`. Allows setting value via query parameter or request header. For Koa and Express.


Version published
Weekly downloads
926
decreased by-22.45%
Maintainers
1
Install size
43.3 kB
Created
Weekly downloads
 

Readme

Source

request-id

Build Status NPM version NPM downloads LICENSE

Allows you to identify client requests within non-sequential logs such as Syslog by adding a response header of X-Request-Id. Allows setting value via query parameter or request header. For Koa and Express.

$ npm install request-id

Usage

Quick Start (koa or express)
# koa
var requestId = require('request-id');
var app = require('koa')();
app.use(requestId());

# express
var requestId = require('request-id/express');
var app = require('express')();
app.use(requestId());
Random ID
% curl example.com
//=> X-Client-ID: a37cacc3-71d5-40f0-a329-a051a3949ced
Set ID via request header
% curl -H 'X-Request-ID:a37cacc3-71d5-40f0-a329-a051a3949ced' example.com
//=> X-Request-ID: a37cacc3-71d5-40f0-a329-a051a3949ced
Set ID via query param
% curl example.com?requestId=a37cacc3-71d5-40f0-a329-a051a3949ced
//=> X-Request-ID: a37cacc3-71d5-40f0-a329-a051a3949ced

Options

Custom Response Header (default: X-Request-Id)
app.use(requestId({
  resHeader: 'X-Client-ID'
}));

% curl example.com
//=> X-Client-ID: a37cacc3-71d5-40f0-a329-a051a3949ced
Custom Request Header (default: X-Request-Id)

Keep in mind that changing the request header does not have any effect on the default response header. If you want them to match, you'll need to set both .resHeader and .reqHeader.

app.use(requestId({
  reqHeader: 'X-Client-ID'
}));

% curl -H 'X-Client-ID:a37cacc3-71d5-40f0-a329-a051a3949ced' example.com
//=> X-Request-ID: a37cacc3-71d5-40f0-a329-a051a3949ced
Custom Query Parameter (default: requestId)
app.use(requestId({
  paramName: 'requestId'
}));

% curl example.com?requestId=a37cacc3-71d5-40f0-a329-a051a3949ced
//=> X-Request-ID: a37cacc3-71d5-40f0-a329-a051a3949ced
Custom Value Generator Function (default: node-uuid.v4)
app.use(requestId({
  generator: function () { return 'ABC'; }
}));

% curl example.com
//=> X-Request-ID: ABC

Alternatives

License

MIT

Keywords

FAQs

Last updated on 26 Dec 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc