pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
25 lines
495 B
25 lines
495 B
from typing import Union
|
|
|
|
from fastapi import Depends, FastAPI
|
|
from typing_extensions import Annotated
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
async def common_parameters(
|
|
q: Union[str, None] = None, skip: int = 0, limit: int = 100
|
|
):
|
|
return {"q": q, "skip": skip, "limit": limit}
|
|
|
|
|
|
CommonsDep = Annotated[dict, Depends(common_parameters)]
|
|
|
|
|
|
@app.get("/items/")
|
|
async def read_items(commons: CommonsDep):
|
|
return commons
|
|
|
|
|
|
@app.get("/users/")
|
|
async def read_users(commons: CommonsDep):
|
|
return commons
|
|
|