{"id":22025177,"url":"https://github.com/drexed/grape-throttler","last_synced_at":"2026-04-18T01:37:47.330Z","repository":{"id":33003861,"uuid":"149340661","full_name":"drexed/grape-throttler","owner":"drexed","description":"Gem for throttling grape requests.","archived":false,"fork":false,"pushed_at":"2023-03-17T05:29:22.000Z","size":38,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-04T07:36:28.935Z","etag":null,"topics":["grape","middleware","ruby","throttle"],"latest_commit_sha":null,"homepage":"https://drexed.github.io/grape-throttler","language":"Ruby","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drexed.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-18T19:22:56.000Z","updated_at":"2021-07-22T19:40:32.000Z","dependencies_parsed_at":"2024-11-30T07:14:55.663Z","dependency_job_id":"7de856fe-bc3f-443a-a5d6-6446ad3e7c33","html_url":"https://github.com/drexed/grape-throttler","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"f7f8d72cbb48643daa531196580febb3a8baca20"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/drexed/grape-throttler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Fgrape-throttler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Fgrape-throttler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Fgrape-throttler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Fgrape-throttler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drexed","download_url":"https://codeload.github.com/drexed/grape-throttler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Fgrape-throttler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31953515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"ssl_error","status_checked_at":"2026-04-18T00:39:20.671Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["grape","middleware","ruby","throttle"],"created_at":"2024-11-30T07:14:48.718Z","updated_at":"2026-04-18T01:37:47.299Z","avatar_url":"https://github.com/drexed.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GrapeThrottler\n\n[![Gem Version](https://badge.fury.io/rb/grape-throttler.svg)](http://badge.fury.io/rb/grape-throttler)\n[![Build Status](https://travis-ci.org/drexed/grape-throttler.svg?branch=master)](https://travis-ci.org/drexed/grape-throttler)\n\nGrapeThrottler provides a simple endpoint-specific throttling mechanism for Grape.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'grape-throttler'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install grape-throttler\n\n## Table of Contents\n\n* [Configuration](#configuration)\n* [Endpoint](#endpoint)\n\n## Configuration\nIn your Grape API, install the middleware which will do the throttling. At a minimum, it requires a Redis instance for caching as the `cache` parameter.\n\n**Simple Case**\n\n```ruby\nuse GrapeThrottler::Middleware::ThrottleMiddleware, cache: Redis.new\n```\n\nIn this simple case, you just set up the middleware, and pass it a Redis instance.\n\n**Advanced Case**\n\n```ruby\nuse GrapeThrottler::Middleware::ThrottleMiddleware, cache: $redis, user_key: -\u003e(env) do\n  # Use the current_user's id as an identifier\n  user = current_user\n  user.nil? ? nil : user.id\nend\n```\n\nIn this more advanced case, the Redis instance is in the global variable `$redis`.\n\nThe `user_key` parameter is a function that can be used to determine a custom identifier for a user. This key is used to form the Redis key to identify this user uniquely. It defaults to the IP address. The `env` parameter given to the function is the Rack environment and can be used to determine information about the caller.\n\n**Logging**\n\nThe gem will log errors to $stdout by default. If you prefer a different logger you can use the `logger` option to pass in your own logger.\n\n```ruby\nuse GrapeThrottler::Middleware::ThrottleMiddleware, cache: Redis.new, logger: Logger.new('my_custom_log.log')\n```\n\n## Endpoint\n\nThis gem adds a `throttle` DSL-like method that can be used to throttle different endpoints differently.\n\nThe `throttle` method takes a Hash of the period to throttle, and the maximum allowed hits. After the maximum, the middleware throws an error with Grape's `error!` function.\n\nSupported predefined periods are: `:hourly`, `:daily`, `:monthly`.\n\nExample:\n\n```ruby\nclass API \u003c GrapeThrottler::API\n  resources :users do\n\n    # Allow start of competition only every 10 minutes\n    desc 'Start competition'\n    throttle period: 10.minutes, limit: 1\n    params do\n      requires :id, type: Integer, desc: 'id'\n    end\n    post '/:id/competition' do\n      User.find(params[:id]).start_competition\n    end\n\n    # 3 times a day max\n    desc 'Fetch a user'\n    throttle daily: 3\n    params do\n      requires :id, type: Integer, desc: 'id'\n    end\n    get '/:id' do\n      User.find(params[:id])\n    end\n\n    # Once a month or the user will go crazy\n    desc 'Poke a user'\n    throttle monthly: 1\n    params do\n      requires :id, type: Integer, desc: 'id'\n    end\n    post '/:id/poke' do\n      User.find(params[:id]).poke\n    end\n\n    # No limit to the amount we can annoy users\n    desc 'Annoy a user'\n    params do\n      requires :id, type: Integer, desc: 'id'\n    end\n    post '/:id/annoy' do\n      User.find(params[:id]).annoy\n    end\n  end\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/grape-throttler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Lite::Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/grape-throttler/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrexed%2Fgrape-throttler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrexed%2Fgrape-throttler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrexed%2Fgrape-throttler/lists"}