Elixir Plug for Ralitobu, the Rate Limiter with Token Bucket algorithm
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
examples
lib/ralitobu
test
.credo.exs
.gitignore
.travis.yml
LICENSE
Makefile
README.md
mix.exs
mix.lock

README.md

Ralitobu.Plug

A Plug for Ralitobu

Usage

# bucketize on remote IP, allow 10 req/s
plug Ralitobu.Plug, on_ip: true, limit: 10, lifetime: 1_000

Example

$ curl -i http://localhost:4000/

HTTP/1.1 200 OK
server: Cowboy
date: Sun, 24 Apr 2016 12:44:37 GMT
content-length: 12
cache-control: max-age=0, private, must-revalidate
ratelimit-limit: 3
ratelimit-remaining: 0
ratelimit-reset: 2

hello world
$ curl -i http://localhost:4000/

HTTP/1.1 429 Too Many Requests
server: Cowboy
date: Sun, 24 Apr 2016 12:44:38 GMT
content-length: 64
cache-control: max-age=0, private, must-revalidate
ratelimit-limit: 3
ratelimit-remaining: 0
ratelimit-reset: 1
retry-after: 1
content-type: application/json; charset=utf-8

{"status": 429, "error": "Too Many Requests", "retry_after": 1}