Coder Social home page Coder Social logo

chentsulin / request-id.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wilmoore/request-id.js

0.0 3.0 0.0 27 KB

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.

License: MIT License

JavaScript 100.00%

request-id.js's Introduction

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

request-id.js's People

Contributors

madbence avatar pjanuario avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.