Skip to content
Discussion options

You must be logged in to vote

From a user perspective, isn’t it simpler to subclass JSONResponse once and reuse the class everywhere, rather than having to remember to import the custom encoder and pass it to every single return JSONResponse()?

# your_module/responses.py
from starlette.responses import JSONResponse as BaseJSONResponse


class JSONResponse(BaseJSONResponse):
    def render(self, content: Any) -> bytes:
        … 

# Then everywhere in your code:
from your_module.responses import JSONResponse

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gregorio-clara
Comment options

Answer selected by Kludex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants