From 31c88185b2f3052fec88e685eaf614a1f4478669 Mon Sep 17 00:00:00 2001 From: Laurent Savaete Date: Thu, 1 Oct 2020 14:02:49 +0100 Subject: [PATCH] Link to docs from README --- README.md | 43 ++----------------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 34eb88c..bb0af6f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ A rate limiting library for Starlette and FastAPI adapted from [flask-limiter](h Note: this is alpha quality code still, the API may change, and things may fall apart while you try it. +The documentation is on [read the docs](https://slowapi.readthedocs.io/en/latest/). + # Quick start ## Installation @@ -14,47 +16,6 @@ Note: this is alpha quality code still, the API may change, and things may fall $ pip install slowapi ``` -## Starlette - -```python - from starlette.applications import Starlette - from slowapi import Limiter, _rate_limit_exceeded_handler - from slowapi.util import get_remote_address - - limiter = Limiter(key_func=get_remote_address) - app = Starlette() - app.state.limiter = limiter - app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) - - @limiter.limit("5/minute") - async def homepage(request: Request): - return PlainTextResponse("test") - - app.add_route("/home", homepage) -``` - -The above app will have a route `t1` that will accept up to 5 requests per minute. Requests beyond this limit will be answered with an HTTP 429 error, and the body of the view will not run. - -## FastAPI - -```python - from fastapi import FastAPI - from slowapi import Limiter, _rate_limit_exceeded_handler - from slowapi.util import get_remote_address - - limiter = Limiter(key_func=get_remote_address) - app = FastAPI() - app.state.limiter = limiter - app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) - - @app.get("/home") - @limiter.limit("5/minute") - async def homepage(request: Request): - return PlainTextResponse("test") -``` - -This will provide the same result, but with a FastAPI app. - # Features Most feature are coming from (will come from) FlaskLimiter and the underlying [limits](https://limits.readthedocs.io/).