Coverage for docs_src/response_change_status_code/tutorial001.py: 100%
9 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
1from fastapi import FastAPI, Response, status 1abcdef
3app = FastAPI() 1abcdef
5tasks = {"foo": "Listen to the Bar Fighters"} 1abcdef
8@app.put("/get-or-create-task/{task_id}", status_code=200) 1abcdef
9def get_or_create_task(task_id: str, response: Response): 1abcdef
10 if task_id not in tasks: 1ghijkl
11 tasks[task_id] = "This didn't exist before" 1ghijkl
12 response.status_code = status.HTTP_201_CREATED 1ghijkl
13 return tasks[task_id] 1ghijkl