View Source PlugLimit.FixedWindow (PlugLimit v0.1.0)
Fixed window rate limiter Plug.
PlugLimit.FixedWindow is a convenience wrapper build on top of a PlugLimit plug.
Module provides syntactic sugar for fixed window algorithm specific options.
usage
Usage
Example usage:
#lib/my_app_web/controllers/page_controller.ex
plug PlugLimit.FixedWindow,
[
limit: 10,
ttl: 60,
key: {MyApp.RateLimiter, :my_key, "page_controller:fixed_window"}
]
when action in [:create]Action :create in PageController will be protected by fixed window rate-limiter.
Users will be able to issue up to 10 requests in 60 seconds time window.
Example code above corresponds to the following direct PlugLimit usage:
#lib/my_app_web/controllers/page_controller.ex
plug PlugLimit,
[
limiter: :fixed_window,
opts: [10, 60],
key: {MyApp.RateLimiter, :my_key, "page_controller:fixed_window"}
]
when action in [:create]
configuration
Configuration
Configuration options:
:limit- requests limit. Required.:ttl- rate-limiter time to live (time-window length) defined as number of seconds. Required.:key- same asPlugLimit:keyconfiguration option. Required.