[!WARNING - End-of-Life - 2024-12-20] This library is End-of-Life. With the 7.x release, it s much easier to create your own rate limiters. But shipping a common plug do not make sense anymore. Please consider using custom function plugs. See the Hammer documentation for more information.
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
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.
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