{"id":15063672,"url":"https://github.com/devstopfix/plug-ratelimit","last_synced_at":"2026-01-01T21:58:50.107Z","repository":{"id":57534957,"uuid":"76723535","full_name":"devstopfix/plug-ratelimit","owner":"devstopfix","description":"Rate limit plug for Elixir HTTP APIs","archived":false,"fork":false,"pushed_at":"2021-02-06T19:18:21.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-24T09:43:57.051Z","etag":null,"topics":["elixir","elixir-library","plug"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/devstopfix.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":"2016-12-17T12:44:05.000Z","updated_at":"2022-08-09T13:18:39.000Z","dependencies_parsed_at":"2022-09-26T18:21:48.773Z","dependency_job_id":null,"html_url":"https://github.com/devstopfix/plug-ratelimit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devstopfix/plug-ratelimit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devstopfix%2Fplug-ratelimit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devstopfix%2Fplug-ratelimit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devstopfix%2Fplug-ratelimit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devstopfix%2Fplug-ratelimit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devstopfix","download_url":"https://codeload.github.com/devstopfix/plug-ratelimit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devstopfix%2Fplug-ratelimit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28164128,"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","status":"online","status_checked_at":"2026-01-01T02:00:06.694Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["elixir","elixir-library","plug"],"created_at":"2024-09-25T00:05:54.675Z","updated_at":"2026-01-01T21:58:50.092Z","avatar_url":"https://github.com/devstopfix.png","language":"Elixir","readme":"# Rate Limit Plug\n\n[Elixir](http://elixir-lang.org/) [Plug](https://hexdocs.pm/plug/readme.html) giving requests per second rate limiting capability.\n\nA resource can be protected by a pro-rata rate limit. For example a limit of 4 requests a second will allow a request every 250ms - you cannot use up all requests in the first few milliseconds of a period. Note this applies to the entire router - the library needs to be extended to handle individual paths.\n\nThe response code when the limit is exceeded is [429 Too Many Requests](https://tools.ietf.org/html/rfc6585#section-4). This plug uses the [Token Bucket Algorithm](https://en.wikipedia.org/wiki/Token_bucket).\n\n[![Build Status](https://github.com/devstopfix/plug-ratelimit/workflows/ci/badge.svg)](https://github.com/devstopfix/plug-ratelimit/actions)\n[![Hex.pm](https://img.shields.io/hexpm/v/plug_ratelimit.svg?style=flat-square)](https://hex.pm/packages/plug_ratelimit)\n\n\n## Install\n\nAdd `:plug_ratelimit` to your list of dependencies in mix.exs:\n\n```elixir\n  {:plug_ratelimit, \"~\u003e 0.21\"}\n```\n\n## Example\n\nThere is an example app in [example/demo.exs](example/demo.exs). To run:\n\n```bash\nmix run --no-halt example/demo.exs\n```\n\nThen call enough times to exceed the 4 req/sec limit:\n\n```bash\nseq 5 | xargs -Iz curl -w \" %{http_code}\\n\" http://localhost:4000/\n\n  ok 200\n  ok 200\n  ok 200\n  ok 200\n  Too Many Requests 429\n```\n\n### Dev\n\nStart REPL:\n\n    iex -S mix\n\nLoad plug:\n\n```elixir\nc \"lib/plug/ratelimit.ex\"\n{:ok, _} = Plug.Adapters.Cowboy.http Plug.Ratelimit, [requests_per_second: 4]\n```\n\nExercise:\n\n    curl http://localhost:4000/\n\n    ab -n 5 http://127.0.0.1:4000/\n\nor run `curl` multiple times:\n\n    seq 5 | xargs -Iz curl http://localhost:4000/\n\n\n## Credits\n\n* This library uses a Stern-Brocot tree to find a good ratio of the number of tokens to add to the bucket at a given interval - this ratio is a variation of the algorithm described in [John D. Cook's Best rational approximation](https://www.johndcook.com/blog/2010/10/20/best-rational-approximation/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevstopfix%2Fplug-ratelimit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevstopfix%2Fplug-ratelimit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevstopfix%2Fplug-ratelimit/lists"}