1.依赖包下载
pip install fastapi[all]
2.get请求
from fastapi import FastAPI # 导入fastapi
from starlette.requests import Request
app = FastAPI()
@app.get("/test/")
def test(key,request: Request):
print(key)
data = {}
data["key"] = "hello fastapi"
data["param"] = key
return data
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8000)
运行脚本
uvicorn main:app --reload