When you are creating apis you want them to safe from a robot requests here is the gem to safe you from these kind of traffic. for example a hacker created a script to make 1 DOS attack to your site so you can save yourself from that attack.
You should have redis gem in your gemfile redis up and running. you need to set a redis path in you initializers/request_throttler.rb
$ config.store = Redis.new(url: 'localhost:6379', namespace: 'request_throttler')
Add this line to your application's Gemfile:
gem 'request_throttler'
And then execute:
$ bundle
Or install it yourself as:
$ gem install request_throttler
To copy request throttler config file:
$ rails g request_throttler
create a method to use before filter for you all requests to check the threshold for you apis use this mehtod:
$ include RequestThrottler # in your applicatio controller
$ threshold?(key) # true or false
If its value true then take action. the key can be request user system ip or access_token
- Fork it ( https://github.com/dilkhush/request_throttler/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request