{"id":13878134,"url":"https://github.com/jeremy/rack-ratelimit","last_synced_at":"2025-04-05T20:05:23.574Z","repository":{"id":6189382,"uuid":"7419837","full_name":"jeremy/rack-ratelimit","owner":"jeremy","description":"Flexible rate limiting for your Rack apps","archived":false,"fork":false,"pushed_at":"2022-01-07T10:27:35.000Z","size":26,"stargazers_count":133,"open_issues_count":3,"forks_count":13,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-29T19:04:24.513Z","etag":null,"topics":["rack","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/jeremy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-03T08:32:49.000Z","updated_at":"2025-03-22T14:19:33.000Z","dependencies_parsed_at":"2022-09-05T22:40:32.431Z","dependency_job_id":null,"html_url":"https://github.com/jeremy/rack-ratelimit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremy%2Frack-ratelimit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremy%2Frack-ratelimit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremy%2Frack-ratelimit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremy%2Frack-ratelimit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeremy","download_url":"https://codeload.github.com/jeremy/rack-ratelimit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393568,"owners_count":20931812,"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":["rack","ruby"],"created_at":"2024-08-06T08:01:40.777Z","updated_at":"2025-04-05T20:05:23.550Z","avatar_url":"https://github.com/jeremy.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"Rack::Ratelimit\n===============\n\n* Run multiple rate limiters in a single app\n* Scope each rate limit to certain requests: API, files, GET vs POST, etc.\n* Apply each rate limit by request characteristics: IP, subdomain, OAuth2 token, etc.\n* Flexible time window to limit burst traffic vs hourly or daily traffic:\n    100 requests per 10 sec, 500 req/minute, 10000 req/hour, etc.\n* Fast, low-overhead implementation in memcache using counters for discrete timeslices:\n    timeslice = window * ceiling(current time / window)\n    memcache.incr(counter for timeslice)\n\n\nConfiguration\n-------------\n\nTakes a block that classifies requests for rate limiting. Given a\nRack env, return a string such as IP address, API token, etc. If the\nblock returns nil, the request won't be rate-limited. If a block is\nnot given, all requests get the same limits.\n\nRequired configuration:\n* rate: an array of [max requests, period in seconds]: [500, 5.minutes]\n\nand one of\n* cache: a Dalli::Client instance\n* redis: a Redis instance\n* counter: Your own custom counter. Must respond to `#increment(classification_string, end_of_time_window_timestamp)` and return the counter value after increment.\n\nOptional configuration:\n* name: name of the rate limiter. Defaults to 'HTTP'. Used in messages.\n* conditions: array of procs that take a rack env, all of which must\n    return true to rate-limit the request.\n* exceptions: array of procs that take a rack env, any of which may\n    return true to exclude the request from rate limiting.\n* logger: responds to #info(message). If provided, the rate limiter\n    logs the first request that hits the rate limit, but none of the\n    subsequently blocked requests.\n* error_message: the message returned in the response body when the rate\n    limit is exceeded. Defaults to \"\u003cname\u003e rate limit exceeded. Please\n    wait \u003cperiod\u003e seconds then retry your request.\"\n\n\nExamples\n--------\n\nRate-limit bursts of POST/PUT/DELETE requests by IP address\n\n    use(Rack::Ratelimit, name: 'POST',\n      exceptions: -\u003e(env) { env['REQUEST_METHOD'] == 'GET' },\n      rate:   [50, 10.seconds],\n      cache:  Dalli::Client.new,\n      logger: Rails.logger) { |env| Rack::Request.new(env).ip }\n\nRate-limit API traffic by user (set by Rack::Auth::Basic)\n\n    use(Rack::Ratelimit, name: 'API',\n      conditions: -\u003e(env) { env['REMOTE_USER'] },\n      rate:   [1000, 1.hour],\n      redis:  Redis.new(ratelimit_redis_config),\n      logger: Rails.logger) { |env| env['REMOTE_USER'] }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremy%2Frack-ratelimit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeremy%2Frack-ratelimit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremy%2Frack-ratelimit/lists"}