/Python Web 开发实战
16
第1章 FastAPI 入门

FastAPI 是一个现代、高性能的 Python Web 框架,基于标准 Python 类型提示,用于构建 API。

1.1 安装与快速开始
bash

pip install fastapi uvicorn
1.2 第一个 API
python

from fastapi import FastAPI

app = FastAPI()

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

运行服务:

bash

uvicorn main:app --reload