url:

http://127.0.0.1:8000/items/?skip=0&limit=10
http://127.0.0.1:8000/items/?skip=20

route:

from fastapi import FastAPI

app = FastAPI()

fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]


@app.get("/items/")
#默认值 skip = 0  limit = 10
async def read_item(skip: int = 0, limit: int = 10):
    return fake_items_db[skip : skip + limit]

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code