Skip to content

Latest commit

 

History

History
72 lines (46 loc) · 1.79 KB

File metadata and controls

72 lines (46 loc) · 1.79 KB

Grape::Attack forked central edition

A forked version of the Grape::Attack middleware focused exclusively on global throttling.

Why Fork This?

It's Rack::Attack for Grape. That's great! But there was a need for global throttling as the default. Like its ancestor, this fork is meant to be dead simple with minimal configuration.

There's a DSL to throttle your Grape API endpoints that works a lot like Wine Bouncer.

Getting Started

Read up on Grape::Attack's installation and default usage.

Installation

Add this line to your application's Gemfile:

gem "grape-attack", github: "nschneble/grape-attack"

Then execute:

$ bundle install

Usage

Mount the middleware in your API:

class MyApi < Grape::API
  use Grape::Attack::Throttle
end

Define global throttling in an initializer (defaults below):

# config/initializers/grape_attack.rb

Grape::Attack.configure do |config|
  config.throttle_limit = 600
  config.throttle_interval = 1.hour
end

Then enable for your Grape endpoints using the throttle DSL:

class MyApi < Grape::API
  use Grape::Attack::Throttle

  resources :contacts do
    throttle
    get do
      Contact.all
    end
  end
end

That's it!

More Information

Refer to Grape::Attack for information on how exceptions are raised, expected HTTP responses, and more.

License

The gem is available as open source under the terms of the MIT License.