You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
662 B
Python

from fastapi import APIRouter
# 创建一个 APIRouter 实例。
# APIRouter 类似于 FastAPI 实例,但它用于定义一组相关的路由。
# 它可以被“包含”到主 FastAPI 应用中。
router = APIRouter()
# 定义获取所有 items 的路由
@router.get("/items/")
async def read_items():
"""
获取所有 item 的列表。
"""
return [{"item_id": "Foo", "name": "Foo Bar"}, {"item_id": "Baz", "name": "Baz Qux"}]
# 定义创建一个新 item 的 POST 路由
@router.post("/items/")
async def create_item():
"""
创建一个新 item。
"""
return {"status": "success", "message": "Item created successfully!"}