Skip to content

Need Rate Limiting on Basis of Request Body for a POST API #179

Discussion options

You must be logged in to vote

sure, sorry for the time I took! Here is a quick example, with comments:

async def limit_dependency(request: Request):
    # slowapi package is only designed to work as a decorator @limiter.limit
    # but fastapi intended to use Dependency Injection system, 
    # that means that we do not have access to that data on decorator execution step.
    # This function is kinda weird, but it allows us to use slowapi as is and integrate it
    # into our app dependencies workflow
    limiter: Limiter = request.app.state.limiter

    # we use this decorator as a trick, so that the limiter key use the endpoint func path
    # instead of our dummy func here.
    # Using @wraps would cause error sin…

Replies: 4 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@shivamneeraj2311
Comment options

@thentgesMindee
Comment options

Comment options

You must be logged in to vote
4 replies
@thentgesMindee
Comment options

Answer selected by thentgesMindee
@thentgesMindee
Comment options

@shivamneeraj2311
Comment options

@thentgesMindee
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #178 on January 09, 2024 15:57.