1.0.3 • Published 8 months ago

@bbc/http-transport-rate-limiter v1.0.3

Weekly downloads
127
License
Apache-2.0
Repository
github
Last release
8 months ago

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);
}
1.0.2

8 months ago

1.0.3

8 months ago

1.0.1

5 years ago

1.0.0

6 years ago

0.0.1

7 years ago