{"id":14981897,"url":"https://github.com/abhisekp/rate-limiter-api","last_synced_at":"2025-10-29T09:31:27.332Z","repository":{"id":10545238,"uuid":"66101239","full_name":"abhisekp/rate-limiter-api","owner":"abhisekp","description":":alarm_clock: :watch: A simple library to easily manage rate limits of APIs without any hassles.","archived":false,"fork":false,"pushed_at":"2023-11-30T14:30:51.000Z","size":310,"stargazers_count":5,"open_issues_count":179,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-29T06:22:15.929Z","etag":null,"topics":["babeljs","callback","javascript","library","nodejs","promise","rate-limits","stamp"],"latest_commit_sha":null,"homepage":"https://rate-limiter-api.js.org","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhisekp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-08-19T17:46:26.000Z","updated_at":"2020-07-28T12:30:03.000Z","dependencies_parsed_at":"2023-10-15T03:21:07.719Z","dependency_job_id":"4cd98f61-860a-4319-9f89-6a3852a8f427","html_url":"https://github.com/abhisekp/rate-limiter-api","commit_stats":{"total_commits":55,"total_committers":4,"mean_commits":13.75,"dds":"0.12727272727272732","last_synced_commit":"b6e0c597533ad115fdab0e5b67526df0b38d8dc5"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhisekp%2Frate-limiter-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhisekp%2Frate-limiter-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhisekp%2Frate-limiter-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhisekp%2Frate-limiter-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhisekp","download_url":"https://codeload.github.com/abhisekp/rate-limiter-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219857951,"owners_count":16556049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babeljs","callback","javascript","library","nodejs","promise","rate-limits","stamp"],"created_at":"2024-09-24T14:04:27.236Z","updated_at":"2025-10-29T09:31:26.948Z","avatar_url":"https://github.com/abhisekp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003ca id=\"app-top\"\u003e\u003c/a\u003e Rate Limiter API\nA simple library to easily manage rate limits of APIs without any hassles.\n\n[![Rate Limiter API image](http://i.imgur.com/JDFpgQZ.jpg \"Rate Limiter API image\")](#app-top)\n\n[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors) [![MIT License](https://img.shields.io/badge/License-MIT-56A902.svg?style=flat-square\u0026maxAge=2592000)](LICENSE) [![npm version](https://img.shields.io/npm/v/rate-limiter-api.svg)](https://badge.fury.io/js/rate-limiter-api) [![Join the chat at https://gitter.im/abhisekp/rate-limiter-api](https://badges.gitter.im/abhisekp/rate-limiter-api.svg)](https://gitter.im/abhisekp/rate-limiter-api?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fabhisekp%2Frate-limiter-api.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fabhisekp%2Frate-limiter-api?ref=badge_shield)\n \n\n## \u003ca id=\"toc\"\u003e\u003c/a\u003e Table of Contents\n- [How to Use](#usage)\n  - [Browser](#usage-browser)\n  - [NodeJS](#usage-nodejs)\n- [Public API](#public-api)\n- [Stats](#stats)\n- [Technologies Used](#techs)\n- [Help \u0026 Support](#help)\n- [Contributors](#contrib)\n- [License](#license)\n- [Contact](#contact)\n\n\n## \u003ca id=\"usage\"\u003e\u003c/a\u003eUsage \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e⮭\u003c/kbd\u003e\u003c/a\u003e\n#### \u003ca id=\"usage-browser\"\u003e\u003c/a\u003eBrowser \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e⮭\u003c/kbd\u003e\u003c/a\u003e\n```html\n\u003cscript src=\"https://cdn.rawgit.com/abhisekp/rate-limiter-api/master/dist/rate-limiter-api.js\"\u003e\u003c/script\u003e\n\n\u003cscript type=\"text/javascript\"\u003e\n  var rateLimiter = RateLimiterAPI()\n\u003c/script\u003e\n```\n\n#### \u003ca id=\"usage-nodejs\"\u003e\u003c/a\u003eNodeJS \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e⮭\u003c/kbd\u003e\u003c/a\u003e\n```sh\n$ {sudo -H} npm install -S rate-limiter-api\n```\n\n```js\nimport RateLimiterAPI from 'rate-limiter-api'\n```\n\n\n## \u003ca id=\"public-api\"\u003e\u003c/a\u003ePublic Interface \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e⮭\u003c/kbd\u003e\u003c/a\u003e\n- `rateLimiter = RateLimiterAPI({threshold: 5})`\n- `rateLimiter.limit(requestHandler) =\u003e Promise`\n  - `rateLimiter.updateRateLimits` on success to update rates\n  - `requestHandler(responseHandler)` on success to continue\n\n----\n```js\nimport RateLimiterAPI from 'rate-limiter-api'\n\nconst rateLimiter = RateLimiterAPI({\n  threshold: 5, // leave `threshold` amount of api requests intact (minimum: 1)\n})\n```\n\nPass an optional `threshold` value which would limit the total rate limits till the threshold is reached in the current session pulse till rate reset.\n\n----\n```js\nconst request = rateLimiter.limit(requestHandler) //=\u003e Promise\n\nfunction requestHandler(responseHandler) {\n  fetch('https://api.example.com/get')\n    .then((response) =\u003e {\n      rateLimiter.updateRateLimits({\n        rateLimit: response.headers.rateLimit,\n        rateRemaining: response.headers.rateRemaining,\n        rateReset: response.headers.rateReset,\n      })\n\n      responseHandler(null, response.body)\n    })\n    .catch((err) =\u003e {\n      responseHandler(err)\n    })\n}\n```\n\nThe `limit` method is passed a `requestHandler` which would manage the request and then call the node-style `responseHandler` callback (which gets passed by the RateLimiter library to the `requestHandler` function) after the request is successful or unsuccessful accordingly.\n\nThe `request` method returns a `Promise`.\n\n\u003e responseHandler(Error, response)  \nwhere the first parameter is the Error object and the seconds parameter is the `response`.\n\n`responseHandler` callback must be called to continue getting responses.\n\nUpdate the rate limits i.e. `{rateLimit, rateRemaining, rateReset}` got from the header using `updateRateLimits` method.\n\n----\n```js\nrequest\n  .then((response) =\u003e {\n    console.dir(response, {colors:1})\n  })\n  .catch((error) =\u003e {\n    console.error(error.message)\n  })\n```\n\nWhen the request completes, the `Promise` resolves and can be thenable to get the response or error.\n\n## \u003ca id=\"stats\"\u003e\u003c/a\u003eStats \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e⮭\u003c/kbd\u003e\u003c/a\u003e\n\n1 text file.  \n1 unique file.  \n0 files ignored.  \n\nhttps://github.com/AlDanial/cloc v 1.66  T=0.04 s (22.7 files/s, 2516.9 lines/s)\n\nLanguage|files|blank|comment|code\n:---|:---:|:---:|:---:|:---:\nJavaScript|1|12|37|62\n\n\n## \u003ca id=\"techs\"\u003e\u003c/a\u003eTechnologies Used \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e⮭\u003c/kbd\u003e\u003c/a\u003e\n- [**Babel**](http://babeljs.io) — Transpiles modern JS to compatible and runnable JS\n- [**Stamp It**](https://github.com/stampit-org/stampit#readme) - Composable inheritance object creation libray\n- [**Async JS**](https://caolan.github.io/async/index.html) - Utility for asynchronous functions\n- [**Lodash**](https://lodash.com/) - Utility library\n\n## \u003ca id=\"help\"\u003e\u003c/a\u003eHelp \u0026 Support \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e⮭\u003c/kbd\u003e\u003c/a\u003e\n- [**BabelJS**](https://babeljs.slack.com) — BabelJS Slack Chat Room\n- [**nodejs/node**](https://gitter.im/nodejs/node) — NodeJS Gitter Chat Room\n- [**Fun with Stamps**](https://medium.com/@koresar/fun-with-stamps-episode-1-stamp-basics-e0627d81efe0) - Learn StampIt\n\n\n## \u003ca id=\"contrib\"\u003e\u003c/a\u003eContributors \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e⮭\u003c/kbd\u003e\u003c/a\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n| [\u003cimg src=\"https://avatars.githubusercontent.com/u/1029200?v=3\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003eAbhisek Pattnaik\u003c/sub\u003e](http://about.me/abhisekp)\u003cbr /\u003e[💻](https://github.com/abhisekp/rate-limiter-api/commits?author=abhisekp) 🎨 [📖](https://github.com/abhisekp/rate-limiter-api/commits?author=abhisekp) 💡 |\n| :---: |\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\nThis project follows the [all-contributors](https://github.com/kentcdodds/all-contributors#emoji-key) specification.\n\n\u003e **All types of Contributions are Welcome** :pray:\n\n## \u003ca id=\"license\"\u003e\u003c/a\u003eLicense \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e⮭\u003c/kbd\u003e\u003c/a\u003e\n\n[**MIT**](LICENSE) © [**Abhisek Patnaik**](https://github.com/abhisekp)\n\n\u003e ----\n\u003ca id=\"contact\"\u003e\u003c/a\u003e\n\u003cp align=\"center\"\u003e\nTweet \u003ckbd\u003e\u003ca href=\"https://twitter.com/abhisek\"\u003e\u003cb\u003e\u003cimg src=\"https://i.imgur.com/wOPZd0Y.png?1\"\u003e @abhisek\u003c/b\u003e\u003c/a\u003e\u003c/kbd\u003e\u003cbr\u003e\nKnow \u003ckbd\u003e\u003cb\u003e\u003ca href=\"https://about.me/abhisekp\"\u003eabout/abhisekp\u003c/a\u003e\u003c/b\u003e\u003c/kbd\u003e\u003cbr\u003e\nChat with \u003ckbd\u003e\u003ca href=\"https://gitter.im/abhisekp\"\u003e\n\u003cimg src=\"https://i.imgur.com/ThSWa6Y.png?2\"\u003e \u003cb\u003e@abhisekp\u003c/b\u003e\u003c/a\u003e\u003c/kbd\u003e\n\u003c/p\u003e\n\n\u003e ----\n\n\u003cdiv align=\"right\"\u003e\n \u003ca href=\"#toc\" title=\"Table of Contents\"\u003e\u003ckbd\u003e\u003cb\u003eTable of Contents ⮭\u003c/b\u003e\u003c/kbd\u003e\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#app-top\"\u003e\u003ckbd\u003e\u003cb\u003eback to top ⮭\u003c/b\u003e\u003c/kbd\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fabhisekp%2Frate-limiter-api.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fabhisekp%2Frate-limiter-api?ref=badge_large)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhisekp%2Frate-limiter-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhisekp%2Frate-limiter-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhisekp%2Frate-limiter-api/lists"}