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