ex_limiter v1.3.1 ExLimiter.Plug View Source
Plug for enforcing rate limits. The usage should be something like
plug ExLimiter.Plug, scale: 1000, limit: 5
Additionally, you can pass the following options:
:bucket
, a 1-arity function of aPlug.Conn.t
which determines the bucket for the rate limit. Defaults to the phoenix controller, action and remote_ip.:consumes
, a 1-arity function of aPlug.Conn.t
which determines the amount to consume. Defaults to 1 respectively.:decorate
, a 2-arity function which can return an updated conn based on the outcome of the limiter call. The first argument is thePlug.Conn.t
, and the second can be:{:ok, Bucket.t}
{:rate_limited, binary}
Where the second element is the bucket name that triggered the rate limit.
Additionally, you can configure a custom limiter with
config :ex_limiter, ExLimiter.Plug, limiter: MyLimiter
and you can also configure the rate limited response with
config :ex_limiter, ExLimiter.Plug, fallback: MyFallback
MyFallback
needs to implement a function render_error(conn, :rate_limited)
Link to this section Summary
Link to this section Functions
Link to this function
call(conn, config) View Source
Link to this function
decorate(conn, _)
View Source
decorate(conn, _)
View Source
decorate(
Plug.Conn.t(),
{:ok, Bucket.t()} | {:rate_limited, bucket_name :: binary()}
) :: Plug.Conn.t()
decorate( Plug.Conn.t(), {:ok, Bucket.t()} | {:rate_limited, bucket_name :: binary()} ) :: Plug.Conn.t()
Link to this function
get_bucket(conn) View Source
Link to this function
init(opts) View Source
Link to this function