https://github.com/bbc/http-transport-rate-limiter
A global plugin for http-transport to utilise the simple-rate-limiter
https://github.com/bbc/http-transport-rate-limiter
ignorearchive
Last synced: 3 months ago
JSON representation
A global plugin for http-transport to utilise the simple-rate-limiter
- Host: GitHub
- URL: https://github.com/bbc/http-transport-rate-limiter
- Owner: bbc
- License: other
- Created: 2017-08-24T13:59:08.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2025-02-03T14:13:54.000Z (5 months ago)
- Last Synced: 2025-03-28T03:03:29.663Z (3 months ago)
- Topics: ignorearchive
- Language: JavaScript
- Size: 35.2 KB
- Stars: 0
- Watchers: 15
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://npmjs.org/package/@bbc/http-transport-rate-limiter)
[](https://travis-ci.org/bbc/http-transport-rate-limiter)




# http-transport-rate-limiter
A global plugin for http-transport to utilise the [simple-rate-limiter](https://github.com/xavi-/node-simple-rate-limiter).## Usage
Configure the plugin as shown below. You can then use it as a global plugin for http-transport.
```js
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
```js
'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);
}
```