一、FastAPI的安装
参考
【大模型应用开发-FastAPI框架】(一)FastAPI概述和安装-优快云博客
二、接收URL参数
示例代码
from fastapi import FastAPI
import uvicorn
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": f"接口id:{item_id}"}
if __name__ == '__main__':
uvicorn.run('main:app', host='0.0.0.0', port=8000, reload=True, workers=1)
三、运行


本文介绍了FastAPI的基本使用,包括如何安装FastAPI,以及如何定义接收URL参数的路由和运行应用。通过示例展示了创建一个简单的RESTfulAPI服务。
5万+

被折叠的 条评论
为什么被折叠?



