Open stilleshan opened 1 year ago
Hi @stilleshan yes, this should work. See this example in the docs. If your code above does not work, then I believe you've found a bug.
Hi! just stumbled accross this issue. I tried to create default limits for all routes without the decorator like this
limiter = Limiter(key_func=get_remote_address, default_limits=["5/minute"], storage_uri="mongodb://localhost:27017", strategy="moving-window")
But it seems to not work. The mongodb storrage seems not to be the issue, because adding the @limiter.limit("5/minute")
decorator directly to a route works.
Can it be that default_limits
is bugged?
Hi @Snawe yes, it could be a bug in the middleware. But can you check a few points first?
Limiter
('storage_uri
, strategy
)? if it is a bug, this would help isolate under which conditions it appears.Please let us know if any of the above fixes your problem. It might be worth adjusting the docs if they're unclear (or fixing the bug, if indeed you found one!).
Hi @laurentS ! Thanks for your reply and sorry for my very late response. It was actually me. I commented out the line to add the middleware during some testing. everything works fine! Thanks.
If I set the global limit to "10/minute" with default_limits, can some API endpoints receive the global limit even if they don't have a limit decorator, while other endpoints with limit decorators receive the limits set by the decorators?
Here's an example: I want to limit access to the /test endpoint to 3 times, and then limit access to both the / and /home endpoints to a total of 7 times. I don't want to add decorators to / and /home separately.