from fastapi import FastAPI, Response
# 创建FastAPI应用
app = FastAPI()
@app.get("/")
def read_root() -> Response:
return Response("The server is running!")
@app.get("/items/{item_id}")
async def read_item(item_id: int):
return {"item_id": item_id, "name": "The Name of the Item", "description": "A description of the item"}
if __name__ == '__main__':
import uvicorn
import os
# 获取当前文件的文件名,不包含后缀
file_name = os.path.splitext(os.path.basename(__file__))[0]
# 运行FastAPI应用
uvicorn.run(f"{file_name}:app", host="127.0.0.1", port=8000, reload=True)
暂无评论