Coverage for docs_src/custom_response/tutorial009c.py: 100%
12 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-06 08:24 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-06 08:24 +0000
1from typing import Any 1abcdef
3import orjson 1abcdef
4from fastapi import FastAPI, Response 1abcdef
6app = FastAPI() 1abcdef
9class CustomORJSONResponse(Response): 1abcdef
10 media_type = "application/json" 1abcdef
12 def render(self, content: Any) -> bytes: 1abcdef
13 assert orjson is not None, "orjson must be installed" 1ghijkl
14 return orjson.dumps(content, option=orjson.OPT_INDENT_2) 1ghijkl
17@app.get("/", response_class=CustomORJSONResponse) 1abcdef
18async def main(): 1abcdef
19 return {"message": "Hello World"} 1ghijkl