Skip to content

feat: add hammer rate limiter #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

GuilhermePSF
Copy link

@GuilhermePSF GuilhermePSF commented Jul 7, 2025

A Plug for rate limiting requests by IP address and user ID using Hammer.

How It Works

  • Limits IP addresses to # {@ip_limit} requests per # {@interval} ms.
  • Limits authenticated users (via conn.assigns[:current_user_id]) to # {@user_limit} requests per # {@interval} ms.
  • If either limit is exceeded, the request is halted with a 429 Too Many Requests response.

This plug expects conn.assigns[:current_user_id] to be set by an authentication plug earlier in the pipeline.
If not present, the plug will default to treating the user as "anon".

@GuilhermePSF GuilhermePSF requested a review from joaodiaslobo July 7, 2025 21:29
@GuilhermePSF GuilhermePSF self-assigned this Jul 7, 2025
@deployum
Copy link

deployum bot commented Jul 7, 2025

The preview deployment is in progress. 🟡

Open Build Logs

Last updated at: 2025-07-07 21:29:06 CET

@GuilhermePSF GuilhermePSF marked this pull request as ready for review July 7, 2025 21:30
@GuilhermePSF
Copy link
Author

GuilhermePSF commented Jul 8, 2025

At this stage the PR is pretty useless, nothing is made that can make use of a rate limiter.

I advise watching this video from ExlixirCasts to better understand how to use this lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: rate limit requests
1 participant