Rate limiter for Jaguar


class ExampleApi {
  Throttler throttle(_) =>
      new Throttler(new Rate(new Duration(seconds: 10), 100));

  @Get(path: '/hello')
  String sayHello(Context ctx) => 'hello';



Rate class provides an easy to define count per time interval. It is used to specify throttling quote of the Throttler

The constructor of Rate takes interval in Duration and count.

Rate(Duration interval, int count);

To create a rate of 100 requests per 10 seconds:

new Rate(new Duration(seconds: 10), 100);

Id maker

ThrottleIdMaker creates the criteria by which requests are throttled. ThrottleIdMaker is a function that takes Context object and returns a String identifying the request.

typedef FutureOr<String> ThrottleIdMaker(Context ctx);

By default, Throttler uses throttleIdByIp as ThrottleIdMaker. throttleIdByIp throttles requests by remote IP address.


Throttler uses Cache to store request count stats. By default, defaultThrottleCache, which is an InMemoryCache, is used as store.


Throttler sets X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset rate-limit headers with quota, quota remaining and duration in seconds after which quota resets respectively. In case, the quota for the current interval is completely used, Throttler also sets the header Retry-After with duration in seconds after which the client can retry.


Provides Throttler