summary refs log tree commit diff
path: root/README
blob: 7f8bbe118833f7b9600193d188df0a622a406ef8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
NAME
    Plack::Middleware::APIRateLimit - A Plack Middleware for API Throttling

SYNOPSIS
      my $handler = builder {
        enable "APIRateLimit";
        # or
        enable "APIRateLimit", requests_per_hour => 2, backend => "Hash";
        # or
        enable "APIRateLimit", requests_per_hour => 2, backend => ["Redis", {port => 6379, server => '127.0.0.1'}];
        # or
        enable "APIRateLimit", request_per_hour => 2, backend => Redis->new(server => '127.0.0.1:6379');

        sub { [ '200', [ 'Content-Type' => 'text/html' ], ['hello world'] ] };
      };

DESCRIPTION
    Plack::Middleware::APIRateLimit is a Plack middleware for controlling
    API access.

    Set a limit on how many requests per hour is allowed on your API. In the
    case of a authorized request, 3 headers are added:

    X-RateLimit-Limit
      How many requests are authorized by hours

    X-RateLimit-Remaining
      How many remaining requests

    X-RateLimit-Reset
      When will the counter be reseted (in epoch)

  VARIABLES
    backend
        Which backend to use. Currently only Hash and Redis are supported.
        If no backend is specified, Hash is used by default. Backend must
        implement set, get and incr.

    requests_per_hour
        How many requests is allowed by hour.

AUTHOR
    franck cuny <franck@linkfluence.net>

SEE ALSO
LICENSE
    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.