Closed ZeroIntensity closed 5 months ago
As of now, a proper JSON response has to be done through something like this:
from view import new_app import json app = new_app() @app.get("/") async def index(): return json.dumps({"foo": "bar"}), {"content-type": "application/json"} app.run()
This is not at all ideal for view.py, so a much more simple way of doing it should be implemented.
The ideal solution would be:
from view import new_app @app.get("/") async def index(): return {"a": "b"} app.run()
However, this might need some modifications on the C end, since dictionaries are already used for parsing headers, which can cause some collisions:
return {"a": "b"}, {"x-www-foo": "hi"} # view doesn't know which is headers and which is JSON
Instead, perhaps a json() function could be added? Or a JSON response class?
json()
JSON
@app.get("/") async def index(): return json({"hello": "world"}) @app.get("/foo") async def foo(): return JSON({"hello": "world"})
No response
Feature description
As of now, a proper JSON response has to be done through something like this:
This is not at all ideal for view.py, so a much more simple way of doing it should be implemented.
Feature example API
The ideal solution would be:
However, this might need some modifications on the C end, since dictionaries are already used for parsing headers, which can cause some collisions:
Instead, perhaps a
json()
function could be added? Or aJSON
response class?Anything else?
No response