bangproject/bang

Add automatic response type detection

Opened this issue · 0 comments

Is your feature request related to a problem? Please describe.
We have html, json, and text responses. We should automate setting of .conent_type attribute by reading from values of these attributes.

Describe the solution you'd like
If a user sets resp.text then the .content_type should be application/text. Likewise if resp.json has a value then the appropriate value can be set in .content_type for that.

Describe alternatives you've considered

  • We could follow starlette here and differentiate JSONResponse, HTMLResponse,... But these types distinctions are actually quite narrow. The HTMLResponse is just a Response with .media_type: str = "text/html". The JSONResponse on the other hand also adds a .render function that handles encoding.
  • On the other hand, httpx and request compatible APIs encode more in the top-level as enumerable string typed fields.