Module: RequestMeter

Defined in:
lib/request_meter/middleware.rb,
lib/request_meter.rb,
lib/request_meter/version.rb,
lib/request_meter/configuration.rb

Overview

RequestMeter::Middleware is a Rack middleware for API rate limiting.

It checks for a configured API key header and limits requests per key using Redis.

Examples:

Basic usage

use RequestMeter::Middleware

Defined Under Namespace

Classes: Configuration, Middleware, MissingCacheClientError

Constant Summary collapse

VERSION =

Current version of the RequestMeter gem.

Returns:

  • (String)

    the gem version

"0.1.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationRequestMeter::Configuration

Returns current configuration instance.

Returns:



12
13
14
# File 'lib/request_meter.rb', line 12

def configuration
  @configuration
end

Class Method Details

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Configure the RequestMeter settings.

Yields the configuration object to the given block.

Examples:

RequestMeter.configure do |config|
  config.api_key_header = "X-API-Key"
  config.quota_limit = 1000
end

Yield Parameters:



27
28
29
30
# File 'lib/request_meter.rb', line 27

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end