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

9 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import FastAPI, Response, status 1abcde

2 

3app = FastAPI() 1abcde

4 

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

6 

7 

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

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

10 if task_id not in tasks: 1abcde

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

12 response.status_code = status.HTTP_201_CREATED 1abcde

13 return tasks[task_id] 1abcde