A pluggable, configurable rate limiting middleware for Rails APIs with Redis backend, Slack alerts, and endpoint exclusions.
Add this line to your application's Gemfile:
gem 'rails_api_guard'And then execute:
$ bundle installOr install it yourself as:
$ gem install rails_api_guardrails generate rails_api_guard:installAdd this to application.rb if not used generator
config.middleware.use RailsApiGuard::Middleware::RateLimiterEdit config/initializers/rails_api_guard.rb to set request limits, expiry time, Slack alerts, and excluded endpoint patterns.
RailsApiGuard can optionally send Slack alerts whenever a request exceeds the defined rate limit threshold.
To enable Slack alerts, set your Slack webhook URL in the initializer:
# config/initializers/rails_api_guard.rb
RailsApiGuard.configure do |config|
config.slack_webhook_url = ENV["SLACK_WEBHOOK_URL"]
end
## Contributing
Contribution directions are yet to add.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).