FastAPI 入门与 HTTP 协议基础
Quickstart e.g 1 2 3 4 5 6 7 8 9 10 11 12 13 from typing import Union from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} @app.get("/items/{item_id}") def read_item(item_id: int, q: Union[str, None] = None): return {"item_id": item_id, "q": q} 创建 FastAPI 实例: 1 app = FastAPI() 在这一步,创建了一个 FastAPI 应用的实例,它将用于定义和管理应用的各个组件,包括路由。FastAPI 是FastAPI框架的主要类。 2. 定义根路径 / 的路由操作 ...