Coverage for docs_src/custom_response/tutorial009c.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1from typing import Any 1abcdefg

2 

3import orjson 1abcdefg

4from fastapi import FastAPI, Response 1abcdefg

5 

6app = FastAPI() 1abcdefg

7 

8 

9class CustomORJSONResponse(Response): 1abcdefg

10 media_type = "application/json" 1abcdefg

11 

12 def render(self, content: Any) -> bytes: 1abcdefg

13 assert orjson is not None, "orjson must be installed" 1hijklmn

14 return orjson.dumps(content, option=orjson.OPT_INDENT_2) 1hijklmn

15 

16 

17@app.get("/", response_class=CustomORJSONResponse) 1abcdefg

18async def main(): 1abcdefg

19 return {"message": "Hello World"} 1hijklmn