Skip to content

Great work, solution for one of the possible limitations. #235

@jymchng

Description

@jymchng

Hi, great work on slowapi.

I saw on your README.md about your limitation of requiring request: Request to be defined in the end user's endpoint function definition.

In my work with the (as of now: unpublished) fastapi-shield library, I mangled the signature of the endpoint function and set it as the __signature__ attribute of the wrapper which is returned to app.[get, post, ...]. This helps with leveraging on FastAPI's dependency injection mechanism to inject Request object into kwargs of endpoint without having the object as part of end user's endpoint function definition. (It is okay if end user also defines a parameter, e.g. req: Request).

Codes: https://github.com/jymchng/fastapi-shield/blob/5b00e584a7843ca36f2277c4186d13a19859220b/src/fastapi_shield/shield.py#L233

By the way, you might also want to not check (ref: codes) that the parameter with type annotated as Request is named as request, checking that it is annotated as Request is sufficient.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions