slowapi icon indicating copy to clipboard operation
slowapi copied to clipboard

No need of Request in endpoint

Open himalacharya opened this issue 4 years ago • 3 comments

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

himalacharya avatar Jan 12 '21 02:01 himalacharya

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

transfluxus avatar Feb 23 '21 12:02 transfluxus

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

laurentS avatar Feb 24 '21 11:02 laurentS

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!

antoinekrajnc avatar Jun 20 '22 17:06 antoinekrajnc