mirror of
https://github.com/fastapi/fastapi.git
synced 2026-02-14 16:21:08 -05:00
📝 Update source examples and docs from Python 3.9 to 3.10
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import FastAPI, Path
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
q: str, item_id: Annotated[int, Path(title="The ID of the item to get")]
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
@@ -0,0 +1,11 @@
|
||||
from fastapi import FastAPI, Path
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(q: str, item_id: int = Path(title="The ID of the item to get")):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
@@ -0,0 +1,15 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import FastAPI, Path
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get")], q: str
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
@@ -0,0 +1,11 @@
|
||||
from fastapi import FastAPI, Path
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(*, item_id: int = Path(title="The ID of the item to get"), q: str):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
@@ -0,0 +1,15 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import FastAPI, Path
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get", ge=1)], q: str
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
@@ -0,0 +1,13 @@
|
||||
from fastapi import FastAPI, Path
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
*, item_id: int = Path(title="The ID of the item to get", ge=1), q: str
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
@@ -0,0 +1,16 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import FastAPI, Path
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get", gt=0, le=1000)],
|
||||
q: str,
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
@@ -0,0 +1,15 @@
|
||||
from fastapi import FastAPI, Path
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
*,
|
||||
item_id: int = Path(title="The ID of the item to get", gt=0, le=1000),
|
||||
q: str,
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Annotated, Union
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import FastAPI, Path, Query
|
||||
|
||||
@@ -7,10 +7,14 @@ app = FastAPI()
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get")],
|
||||
q: Annotated[Union[str, None], Query(alias="item-query")] = None,
|
||||
*,
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get", ge=0, le=1000)],
|
||||
q: str,
|
||||
size: Annotated[float, Query(gt=0, lt=10.5)],
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
if size:
|
||||
results.update({"size": size})
|
||||
return results
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Union
|
||||
|
||||
from fastapi import FastAPI, Path, Query
|
||||
|
||||
app = FastAPI()
|
||||
@@ -7,10 +5,14 @@ app = FastAPI()
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
item_id: int = Path(title="The ID of the item to get"),
|
||||
q: Union[str, None] = Query(default=None, alias="item-query"),
|
||||
*,
|
||||
item_id: int = Path(title="The ID of the item to get", ge=0, le=1000),
|
||||
q: str,
|
||||
size: float = Query(gt=0, lt=10.5),
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
if size:
|
||||
results.update({"size": size})
|
||||
return results
|
||||
Reference in New Issue
Block a user