@bbc/http-transport-rate-limiter

1.0.3 • Public • Published

NPM downloads Build Status npm license github-issues stars forks

http-transport-rate-limiter

A global plugin for http-transport to utilise the simple-rate-limiter.

Usage

Configure the plugin as shown below. You can then use it as a global plugin for http-transport.

const simpleRateLimiterPlugin = require('@bbc/http-transport-rate-limiter')(count, duration);

The plugin takes two arguments:

  • count: The amount of calls that are allowed per time window
  • duration: The length of the time window to restrict calls within. In milliseconds.

Example

'use strict';

const url = 'http://example.com/';
const simpleRateLimiterPlugin = require('@bbc/http-transport-rate-limiter');

const client = require('@bbc/http-transport').createBuilder()
  .use(simpleRateLimiterPlugin(2, 1000)
  .createClient();

const res = await client
  .get(url)
  .asResponse();
 
if (res.statusCode === 200) {
  console.log(res.body);
}

Readme

Keywords

none

Package Sidebar

Install

npm i @bbc/http-transport-rate-limiter

Weekly Downloads

86

Version

1.0.3

License

Apache-2.0

Unpacked Size

5.43 kB

Total Files

8

Last publish

Collaborators

  • gozcue01-bbc
  • rlfbbc
  • naivinh.ta.bbc
  • gingertonicst
  • bhartn01
  • notten13
  • szpytfire-bbc
  • pjlangley
  • vinodrane
  • cjewell47
  • lexedwardsbbc
  • sbason
  • eobr
  • david.toluhi
  • chriss901
  • pshaw03
  • alexshelley
  • oliviadrury
  • brotherkaif
  • kieranjoyce
  • monsai
  • rosemcnally
  • felixmercermoss
  • katyasa
  • dwalker487
  • amitsavant
  • npmbs
  • vaughr03
  • iuketaylor
  • jamiebower185
  • benjwheeler
  • onlyonehas
  • drrobharper
  • johnnewman
  • ibl
  • simontanner
  • simongregory
  • tonymcbeth