FastApi -- 第一个程序

package安装

pip install fastapi
pip install uvicorn

fastapi应用

# main.py

from fastapi import FastAPI

app = FastAPI()


@app.get("/hello")
def hello():
  return {"Message": "Helllo World"}

调试运行

uvicorn main:app --reload

接口文档

  • 查看返回:http://127.0.0.1:8000/hello
  • 交互式接口文档:http://127.0.0.1:8000/docs
  • 接口文档:http://127.0.0.1:8000/redoc

你可能感兴趣的:(python-learn,fastapi,python)