-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 Request] Provide a JsonResponse class #689
Comments
Use |
I tried to use that, but one problem with that approach, is that you no longer have access to the original data. So for example, it is not possible to have a middleware that inspects the data and does something with it (my use case), or in tests for example. Another problem is that nothing restricts you from changing the underlying text representation. So you could end up with a malformed json body. Also, the data is serialized eagerly, instead of lazily. Which means that you would incur the cost of serializing even if you end up dropping that response. |
I got your point. Both usages may be fine for application code but will never get a chance to land into aiohttp library. |
We have been using aiohttp successfully, however we miss a simpler way of generating json responses.
For such we have a utility classes defining a
JsonResponse
class. Note that using directly aweb.Response
is tedious, as you have to set thecontent_type
, and probably you want to convert to JSON at the very last minute.Our (hacky) implementation is as follows:
I would really love to have JSON support to be much simpler out of the box, and would be happy to contribute a non hacky version.
The text was updated successfully, but these errors were encountered: