mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-23 22:29:34 -05:00
Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
20 lines
451 B
Python
20 lines
451 B
Python
from typing import Any
|
|
|
|
import orjson
|
|
from fastapi import FastAPI, Response
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class CustomORJSONResponse(Response):
|
|
media_type = "application/json"
|
|
|
|
def render(self, content: Any) -> bytes:
|
|
assert orjson is not None, "orjson must be installed"
|
|
return orjson.dumps(content, option=orjson.OPT_INDENT_2)
|
|
|
|
|
|
@app.get("/", response_class=CustomORJSONResponse)
|
|
async def main():
|
|
return {"message": "Hello World"}
|