Skip to content

Grape middleware for global throttling.

License

Notifications You must be signed in to change notification settings

nschneble/grape-attack

 
 

Repository files navigation

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.

About

Grape middleware for global throttling.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 98.9%
  • Shell 1.1%