Home Posts Projects

Changing the default response class of FastAPI

09-09-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)

Related

28-10-2024

FastAPI to include servers when generating OpenAPI spec

07-08-2022

Add global exception handlers to FastAPI app

© 2026 Luke Miloszewski

Email Address GitHub Twitter