Open laurentS opened 3 years ago
This appears to be the implementation approach for this other rate-limiting library for FastAPI.
Awesome work. I think also this pattern fits best with fastAPI and reduces boiler-plate.
You should just be able to create your own dependency like this
@limiter.limit("5/minute")
def rate_limit(request: Request):
return None
@router.get(
"/{user_key}", response_model=Mapping[str, List]]
)
def get_user(
user_key: UUID,
rate_limit = Depends(deps.rate_limit)
) -> Any:
pass
As suggested in this comment it should be possible to make the functionality available as a dependency for FastAPI. It looks like this would not be usable in Starlette, so probably only makes sense if the extra code required is minimal.