-
-
Notifications
You must be signed in to change notification settings - Fork 931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customizable request class #875
Customizable request class #875
Conversation
Dropping by out of curiosity — could you explicit some practical use cases that would motivate the ability to swap the request class? Maybe this is linked to an existing issue? |
I would store this to |
I am building an application that has a custom Request class. This class has extra methods related to it (input validation, helpers to get values from GET/POST, user IP, and many other helpers). In order to make use of it, I have to completely extend Route/HTTPEndpoint/request_response names. It is a huge overhead here. Also, it is useful for frameworks built on top of Starlette. They often have own request classes (look at HttpRequest in Django and Request in DRF). |
@alex-oleshkevich After this whole time, do you still want this feature? Is it something you'd want to discuss? |
Yes, i use custom request time each time. My class has some extra properties and utilities. |
There can be a workaround with a simple decorator that inspects view signature and injects a needed request instance. |
This allows users to change the default
Request
class.There are following customization options:
request_class
on Route constructor:This has higher precedence than
request_class
defined in HTTPEndpoint class.request_class
in HTTPEndpoint: