-
Notifications
You must be signed in to change notification settings - Fork 26
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
Feature to modify body and query_parameters in PiccoloCRUD
#235
Comments
Hi @sarvesh4396 My initial thoughts was using middleware to modify the body. I looked around a bit and found this issue: encode/starlette#495 (comment) It's definitely not easy to do, but I think it's possible. We have a couple of ways of modifying the behaviour of The other is validators. The intended purpose is to add extra validation to endpoints, but you may be able to use these to modify the request. async def my_validator(piccolo_crud: PiccoloCRUD, request: Request):
json = await request.json()
request._json = {**json, 'custom_field': 'hello world'} It might be worth giving that a go. |
hey @dantownsend , |
@sarvesh4396 OK, interesting. When you do |
@dantownsend Yes, It does, query params can be changed through middleware but not the body. |
@sarvesh4396 OK, cool. Do you think this is something we could write a custom hook for? |
@dantownsend I didn't get it, Do you mean by Hooks which are there in piccolo-api? or something else. |
@sarvesh4396 Yeah, we have hooks for PiccoloAPI like In our piccolo_api/piccolo_api/csrf/middleware.py Lines 136 to 139 in 16704dd
|
@dantownsend, It should work ideally, as we can receive the request Object in hooks. |
Currently, PiccoloCRUD exposes all endpoints and we can not change them internally.
If we try to add middleware we can achieve that for query parameters but it can not be done for the body.
Proposed Solution
Add two callable parameters in PiccoloCRUD for manipulation of the body and parameters.
And we can pass
headers
,query
withmodify_query_params
headers
,body
withmodify_body
Then we can update the
dict
at desired placesUse Cases
It will give the ability to manipulate the query operations in the desired way
for example a notes app
If we want to add a note for that user without passing the user_id.
If we are using
jwt
then we can get the user_id from theAuthorization
header and pass it into the bodyalso, It will enable us to get all the notes from that user without passing that param explicitly.
@dantownsend I can do a PR, if the idea is helpful.
The text was updated successfully, but these errors were encountered: