mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-29 03:04:49 -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
8
docs_src/path_params/tutorial001_py310.py
Normal file
8
docs_src/path_params/tutorial001_py310.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_item(item_id):
|
||||
return {"item_id": item_id}
|
||||
8
docs_src/path_params/tutorial002_py310.py
Normal file
8
docs_src/path_params/tutorial002_py310.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_item(item_id: int):
|
||||
return {"item_id": item_id}
|
||||
13
docs_src/path_params/tutorial003_py310.py
Normal file
13
docs_src/path_params/tutorial003_py310.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/users/me")
|
||||
async def read_user_me():
|
||||
return {"user_id": "the current user"}
|
||||
|
||||
|
||||
@app.get("/users/{user_id}")
|
||||
async def read_user(user_id: str):
|
||||
return {"user_id": user_id}
|
||||
13
docs_src/path_params/tutorial003b_py310.py
Normal file
13
docs_src/path_params/tutorial003b_py310.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/users")
|
||||
async def read_users():
|
||||
return ["Rick", "Morty"]
|
||||
|
||||
|
||||
@app.get("/users")
|
||||
async def read_users2():
|
||||
return ["Bean", "Elfo"]
|
||||
8
docs_src/path_params/tutorial004_py310.py
Normal file
8
docs_src/path_params/tutorial004_py310.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/files/{file_path:path}")
|
||||
async def read_file(file_path: str):
|
||||
return {"file_path": file_path}
|
||||
23
docs_src/path_params/tutorial005_py310.py
Normal file
23
docs_src/path_params/tutorial005_py310.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from enum import Enum
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
|
||||
class ModelName(str, Enum):
|
||||
alexnet = "alexnet"
|
||||
resnet = "resnet"
|
||||
lenet = "lenet"
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/models/{model_name}")
|
||||
async def get_model(model_name: ModelName):
|
||||
if model_name is ModelName.alexnet:
|
||||
return {"model_name": model_name, "message": "Deep Learning FTW!"}
|
||||
|
||||
if model_name.value == "lenet":
|
||||
return {"model_name": model_name, "message": "LeCNN all the images"}
|
||||
|
||||
return {"model_name": model_name, "message": "Have some residuals"}
|
||||
Reference in New Issue
Block a user