Open harshraj22 opened 2 years ago
Add rate limiter to the api endpoint.
# https://slowapi.readthedocs.io/en/latest/ from fastapi import FastAPI, Request from slowapi import Limiter, _rate_limit_exceeded_handler from slowapi.util import get_remote_address from slowapi.middleware import SlowAPIMiddleware from slowapi.errors import RateLimitExceeded app = FastAPI() # limiter = Limiter(key_func=get_remote_address, default_limits=["1/minute"]) limiter = Limiter(key_func=get_remote_address) app.state.limiter = limiter app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) @app.get("/") @limiter.limit("1/minute") def read_root(request: Request): return {"Hello": "World"}
Add the rate limiter to the auth service. the other endpoints are/will be protected by API Gateway/ subscription based rate limiter.
auth
Add rate limiter to the api endpoint.