Files
fastapi/fastapi/responses.py
Sebastián Ramírez 94ee932351 Add ORJSONResponse (#1065)
*  Add ORJSONResponse

* 📝 Add tutorial using ORJSONResponse

*  Add test for ORJSONResponse

* 📝 Update index.md
2020-03-01 22:30:58 +01:00

24 lines
797 B
Python

from typing import Any
from starlette.responses import FileResponse # noqa
from starlette.responses import HTMLResponse # noqa
from starlette.responses import JSONResponse # noqa
from starlette.responses import PlainTextResponse # noqa
from starlette.responses import RedirectResponse # noqa
from starlette.responses import Response # noqa
from starlette.responses import StreamingResponse # noqa
from starlette.responses import UJSONResponse # noqa
try:
import orjson
except ImportError: # pragma: nocover
orjson = None # type: ignore
class ORJSONResponse(JSONResponse):
media_type = "application/json"
def render(self, content: Any) -> bytes:
assert orjson is not None, "orjson must be installed to use ORJSONResponse"
return orjson.dumps(content)