Perform rate limiting #1505
Answered
by
hgalytoby
alfonsodipace
asked this question in
Q&A
-
Hi, how can I perform rate limiting on the user requests? @limiter.limit("5/minute")
async def myendpoint(request: Request)
pass |
Beta Was this translation helpful? Give feedback.
Answered by
hgalytoby
Apr 22, 2025
Replies: 1 comment 2 replies
-
def apply_rate_limit(router, path: str, method: str, limit_str: str):
for route in router.routes:
if isinstance(route, APIRoute) and route.path == path and method.upper() in route.methods:
route.endpoint = limiter.limit(limit_str)(route.endpoint)
register_router = fastapi_users.get_register_router(UserRead, UserCreate)
apply_rate_limit(register_router, "/register", "POST", "5/minute")
app.include_router(
register_router,
prefix="/auth",
tags=["auth"],
) It's important to note that you must call I just tested it, and it works without any issues. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
alfonsodipace
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's important to note that you must call
apply_rate_limit
beforeapp.include_router
.I just tested it, and it works without any issues.