laurentS / slowapi

A rate limiter for Starlette and FastAPI
https://pypi.org/project/slowapi/
MIT License
1.21k stars 77 forks source link

No need of Request in endpoint #34

Open himalacharya opened 3 years ago

himalacharya commented 3 years ago

In relation to example in issue #25 , ratelimit works without using Request in endpoint. I havenot used Request in any endpoint of my application but ratelimit works. But documentation strongly suggests to use Request in endpoint. Example:

@router.post('/show',
             tags=["show"],
             name="show:showToAll")
async def show_to_all(background_tasks: BackgroundTasks, user_id = Form(...) ,db: AsyncIOMotorClient = Depends(get_database), Authorize: AuthJWT = Depends(), language: Optional[str] = "en"):
    ****code*****

This works with example of issue #25

transfluxus commented 3 years ago

not for me. I am getting: Exception: No "request" or "websocket" argument on function "<function test at 0x7f2834c39e50>"

laurentS commented 3 years ago

@himalacharya I don't understand how the code would work without the request argument. Can you share a minimal example that reproduces it?

antoinekrajnc commented 2 years ago

Hi @transfluxus , I ran into the same issue. What worked for me is simply to add:

@router.get("/")
@limiter.limit("5/minute")
async def current_transactions(request: Request):
     "YOUR CODE"
     return "something"

eventhough request: Request is not used within your function

Hope that helps!