From 48d5f20096589d1e86192a74be9179207912ed57 Mon Sep 17 00:00:00 2001 From: Joris Hartog Date: Thu, 9 Dec 2021 11:14:14 +0100 Subject: [PATCH 1/2] Fix import issues in examples This commit fixes a couple of bugs in the FastAPI and Starlette examples in the docs. --- docs/index.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index cd1e3a2..6a25374 100644 --- a/docs/index.md +++ b/docs/index.md @@ -18,6 +18,8 @@ $ pip install slowapi ```python from starlette.applications import Starlette + from starlette.responses import PlainTextResponse + from starlette.requests import Request from slowapi import Limiter, _rate_limit_exceeded_handler from slowapi.util import get_remote_address from slowapi.errors import RateLimitExceeded @@ -39,7 +41,7 @@ The above app will have a route `t1` that will accept up to 5 requests per minut ## FastAPI ```python - from fastapi import FastAPI, Request + from fastapi import FastAPI, Request, Response from slowapi import Limiter, _rate_limit_exceeded_handler from slowapi.util import get_remote_address from slowapi.errors import RateLimitExceeded @@ -53,7 +55,7 @@ The above app will have a route `t1` that will accept up to 5 requests per minut @app.get("/home") @limiter.limit("5/minute") async def homepage(request: Request): - return PlainTextResponse("test") + return Response("test") @app.get("/mars") @limiter.limit("5/minute") From bbdadd76743f992cd77002f097225e0f2ccab67f Mon Sep 17 00:00:00 2001 From: Joris Hartog Date: Thu, 9 Dec 2021 11:35:27 +0100 Subject: [PATCH 2/2] Fix duplicate method name bug in FastAPI example Fixes #75 --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 6a25374..e5cb3d7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -54,12 +54,12 @@ The above app will have a route `t1` that will accept up to 5 requests per minut # Note: the route decorator must be above the limit decorator, not below it @app.get("/home") @limiter.limit("5/minute") - async def homepage(request: Request): + async def home(request: Request): return Response("test") @app.get("/mars") @limiter.limit("5/minute") - async def homepage(request: Request, response: Response): + async def mars(request: Request, response: Response): return {"key": "value"} ```