HomePostsProjects

Changing the default response class of FastAPI

September 9, 2022

https://github.com/tiangolo/fastapi/issues/459#issuecomment-536781105

class ORJSONResponse(JSONResponse):
    media_type = "application/json"
 
    def render(self, content: typing.Any) -> bytes:
        return orjson.dumps(content)
 
 
app = FastAPI(default_response_class=ORJSONResponse)

© 2025 Luke Miloszewski

Email AddressGitHubTwitter