Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
long2ice committed Mar 31, 2021
1 parent dd385d6 commit 039f8f0
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Just install from pypi

## Quick Start

FastAPI-Limiter is simple to use, which just provide a dependency `RateLimiter`, the following example allow `2` times request per `5` seconds in route `/`.
FastAPI-Limiter is simple to use, which just provide a dependency `RateLimiter`, the following example allow `2` times
request per `5` seconds in route `/`.

```py
import aioredis
Expand Down Expand Up @@ -95,6 +96,24 @@ async def default_callback(request: Request, response: Response, pexpire: int):
)
```

## Multiple limiters

You can use multiple limiters in one route.

```py
@app.get(
"/multiple",
dependencies=[
Depends(RateLimiter(times=1, seconds=5)),
Depends(RateLimiter(times=2, seconds=15)),
],
)
async def multiple():
return {"msg": "Hello World"}
```

Not that you should note the dependencies orders, keep lower of result of `seconds/times` at the first.

## License

This project is licensed under the
Expand Down

1 comment on commit 039f8f0

@BookerLoL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a better example to perhaps show different times units:

@app.get(
    "/multiple",
    dependencies=[
        Depends(RateLimiter(times=5, seconds=5)),
        Depends(RateLimiter(times=10, minutes=1)),
    ],
)

Something like this so that other people can understand a good use case.

Please sign in to comment.