跳转至

快速开始

环境要求

Python 3.8+版本

安装模块

pip install fastapi
pip install "uvicorn[standard]"

Phasellus posuere in sem ut cursus (1)

编写代码

main.py文件中,编写如下代码:

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}

然后在控制台启动项目

uvicorn main:app --reload --port8000

此时访问localhost:8000/就能看到路由函数返回的 json 数据了。访问localhost:8000/docx可以查看自动生成的 API 文档,并且支持测试。