mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-04 05:33:56 -04:00
📝 Update source examples and docs from Python 3.9 to 3.10 (#14900)
This commit is contained in:
committed by
GitHub
parent
d06ab3f5c7
commit
c9e2277d8b
13
docs_src/response_change_status_code/tutorial001_py310.py
Normal file
13
docs_src/response_change_status_code/tutorial001_py310.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from fastapi import FastAPI, Response, status
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
tasks = {"foo": "Listen to the Bar Fighters"}
|
||||
|
||||
|
||||
@app.put("/get-or-create-task/{task_id}", status_code=200)
|
||||
def get_or_create_task(task_id: str, response: Response):
|
||||
if task_id not in tasks:
|
||||
tasks[task_id] = "This didn't exist before"
|
||||
response.status_code = status.HTTP_201_CREATED
|
||||
return tasks[task_id]
|
||||
Reference in New Issue
Block a user