Skip to content

ExHammer/hammer-plug

Repository files navigation

Hammer.Plug

Build Status Hex.pm Documentation Total Download License

Hammer is a rate-limiter for Elixir, with pluggable storage backends.

This library is a plug helper, to easily add rate-limiting to Phoenix applications, or any Elixir system that uses plug.

Example:

# Allow ten uploads per 60 seconds
plug Hammer.Plug, [
  rate_limit: {"video:upload", 60_000, 10},
  by: {:session, :user_id}
] when action == :upload_video_file

def upload_video_file(conn, _opts) do
  # ...
end

Documentation

See the Hammer documentation page for more info on Hammer itself.

See the Hammer.Plug docs for more info about this library and how to use it, specifically the Hammer.Plug module.

Installation

Hammer-Plug is avaliable available in Hex, the package can be installed by adding hammer_plug to your list of dependencies in mix.exs:

def deps do
  [
    {:hammer, "~> 6.0"},
    {:hammer_plug, "~> 3.0"}
  ]
end