{"id":15502953,"url":"https://github.com/evuez/valve","last_synced_at":"2025-04-10T23:13:03.597Z","repository":{"id":62430722,"uuid":"104755114","full_name":"evuez/valve","owner":"evuez","description":"🍶 An Elixir Plug with pluggable backends to rate-limit requests to your web app.","archived":false,"fork":false,"pushed_at":"2018-03-26T08:09:18.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T23:12:57.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/valve","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/evuez.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":"2017-09-25T13:42:25.000Z","updated_at":"2023-07-25T14:11:42.000Z","dependencies_parsed_at":"2022-11-01T20:30:50.162Z","dependency_job_id":null,"html_url":"https://github.com/evuez/valve","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evuez%2Fvalve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evuez%2Fvalve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evuez%2Fvalve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evuez%2Fvalve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evuez","download_url":"https://codeload.github.com/evuez/valve/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248312135,"owners_count":21082638,"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":[],"created_at":"2024-10-02T09:11:40.523Z","updated_at":"2025-04-10T23:13:03.577Z","avatar_url":"https://github.com/evuez.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Valve\n\nAn Elixir Plug to rate-limit requests to your web app.\n\n## Installation\n\nAdd `valve` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:valve, \"~\u003e 0.2.0\"}]\nend\n```\n\nThen plug it in your pipeline:\n\n```elixir\ndefmodule MyApp.Router do\n  use MyApp, :router\n\n  # ...\n\n  pipeline :api do\n    plug Valve\n\n    # ...\n  end\n```\n\nThe default behavior when reaching the maximum number of requests allowed is to return an [`HTTP 429 (Too Many Requests)`](https://httpstatuses.com/429) with a `Retry-After` header.\nThis can be overridden by passing an `on_flood` option to the plug:\n\n```elixir\nplug Valve, on_flood: fn (conn, retry_after) -\u003e put_status(conn, 418) |\u003e halt() end\n```\n\n## Configuration\n\nPut this in your config:\n\n```elixir\nconfig :valve,\n  rate: {10, 60}, # Give 10 tokens every 60 second\n  max_tokens: 20, # Give at most 20 tokens (also give 20 tokens initially)\n  pool_size: 8, # Number of Valve.Store processes (how many requests can be handled simultaneously)\n  store: Valve.Store.ETS # The storage adapter used to store buckets (you'll need to recompile the library if you change this)\n```\n\n\n## Storage adapters\n\nFor now there's only an ETS backend (`Valve.Store.ETS`), contributions are welcome!\n\n### ETS\n\n```elixir\nconfig :valve, Valve.Store.ETS,\n  table: :my_table, # Defaults to `:valve`\n  ttl: 48 * 3_600, # How much time (in seconds) before an entry should get swept (defaults to a day)\n  sweep_interval: 7_200 * 1000 # How often (in milliseconds) should stale entries be cleaned (defaults to an hour)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevuez%2Fvalve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevuez%2Fvalve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevuez%2Fvalve/lists"}