{"id":15253556,"url":"https://github.com/scttcper/koa-simple-ratelimit","last_synced_at":"2025-04-11T11:17:16.254Z","repository":{"id":46643243,"uuid":"47363953","full_name":"scttcper/koa-simple-ratelimit","owner":"scttcper","description":"Simple rate limiter for Koa.js v2 web framework","archived":false,"fork":false,"pushed_at":"2021-10-02T03:41:10.000Z","size":1328,"stargazers_count":17,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T22:11:59.562Z","etag":null,"topics":["koa","koa2","rate-limits"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/scttcper.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}},"created_at":"2015-12-03T22:10:19.000Z","updated_at":"2021-10-02T03:39:36.000Z","dependencies_parsed_at":"2022-09-06T23:12:18.633Z","dependency_job_id":null,"html_url":"https://github.com/scttcper/koa-simple-ratelimit","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scttcper%2Fkoa-simple-ratelimit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scttcper%2Fkoa-simple-ratelimit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scttcper%2Fkoa-simple-ratelimit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scttcper%2Fkoa-simple-ratelimit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scttcper","download_url":"https://codeload.github.com/scttcper/koa-simple-ratelimit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248381796,"owners_count":21094528,"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":["koa","koa2","rate-limits"],"created_at":"2024-09-29T21:05:26.267Z","updated_at":"2025-04-11T11:17:16.158Z","avatar_url":"https://github.com/scttcper.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-simple-ratelimit\n\n[![NPM version][npm-img]][npm-url]\n[![build status](https://circleci.com/gh/scttcper/ts-trueskill.svg?style=svg)](https://circleci.com/gh/scttcper/ts-trueskill)\n[![coverage][coverage-img]][coverage-url]\n\n\n[npm-img]: https://img.shields.io/npm/v/koa-simple-ratelimit.svg\n[npm-url]: https://npmjs.org/package/koa-simple-ratelimit\n[coverage-img]: https://codecov.io/gh/scttcper/koa-simple-ratelimit/branch/master/graph/badge.svg\n[coverage-url]: https://codecov.io/gh/scttcper/koa-simple-ratelimit\n\n\n Rate limiter middleware for koa v2. Differs from [koa-ratelimit](https://github.com/koajs/ratelimit) by not depending on [ratelimiter](https://github.com/tj/node-ratelimiter) and using redis ttl (time to live) to handle expiration time remaining. This creates only one entry in redis instead of the three that node-ratelimiter does.\n\n## Installation\n\n```sh\nnpm install koa-simple-ratelimit\n```\n\n## Example\n\n```ts\nimport Koa from 'koa';\nimport redis from 'redis';\n\nimport { ratelimit } from 'koa-simple-ratelimit';\n\nconst app = new Koa();\n\n// Apply rate limit\n\napp.use(ratelimit({\n\tdb: redis.createClient(),\n\tduration: 60000,\n\tmax: 100\n}));\n\n// Response middleware\n\napp.use((ctx, next) =\u003e {\n\tctx.body = 'Stuff!';\n\treturn next();\n});\n\napp.listen(4000);\nconsole.log('listening on port http://localhost:4000');\n```\n\n## Options\n\n - `db` redis connection instance\n - `max` max requests within `duration` [2500]\n - `duration` of limit in milliseconds [3600000]\n - `id` id to compare requests [ip]\n - `allowlist` array of ids to allowlist\n - `blocklist` array of ids to blocklist\n - `prefix` redis key prefix [\"limit\"]\n\n## Responses\n\n  Example 200 with header fields:\n\n```\nHTTP/1.1 200 OK\nX-Powered-By: koa\nX-RateLimit-Limit: 100\nX-RateLimit-Remaining: 99\nX-RateLimit-Reset: 1384377793\nContent-Type: text/plain; charset=utf-8\nContent-Length: 6\nDate: Wed, 13 Nov 2013 21:22:13 GMT\nConnection: keep-alive\n\nStuff!\n```\n\n  Example 429 response:\n\n```\nHTTP/1.1 429 Too Many Requests\nX-Powered-By: koa\nX-RateLimit-Limit: 100\nX-RateLimit-Remaining: 0\nX-RateLimit-Reset: 1384377716\nContent-Type: text/plain; charset=utf-8\nContent-Length: 39\nRetry-After: 7\nDate: Wed, 13 Nov 2013 21:21:48 GMT\nConnection: keep-alive\n\nRate limit exceeded, retry in 8 seconds\n```\n\n## License\n\n  MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscttcper%2Fkoa-simple-ratelimit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscttcper%2Fkoa-simple-ratelimit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscttcper%2Fkoa-simple-ratelimit/lists"}