Coverage for docs_src / response_change_status_code / tutorial001_py310.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from fastapi import FastAPI, Response, status 1abcd

2 

3app = FastAPI() 1abcd

4 

5tasks = {"foo": "Listen to the Bar Fighters"} 1abcd

6 

7 

8@app.put("/get-or-create-task/{task_id}", status_code=200) 1abcd

9def get_or_create_task(task_id: str, response: Response): 1abcd

10 if task_id not in tasks: 1efg

11 tasks[task_id] = "This didn't exist before" 1efg

12 response.status_code = status.HTTP_201_CREATED 1efg

13 return tasks[task_id] 1efg