- Add FastAPI application with health check and item CRUD endpoints - Add Pydantic models for request/response validation - Add pytest test suite with 5 passing tests - Add project documentation and run script Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
FastAPI Example
一个最小化的 FastAPI REST API 示例项目。
快速开始
# 创建虚拟环境并安装依赖
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# 启动服务
./run.sh
# 或直接运行
uvicorn app.main:app --reload
API 端点
| 方法 | 路径 | 描述 |
|---|---|---|
| GET | /health | 健康检查 |
| GET | /items | 列出所有项目 |
| POST | /items | 创建新项目 |
| GET | /items/{id} | 获取单个项目 |
测试
source .venv/bin/activate
pytest tests/ -v
API 文档
启动服务后访问:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Description
Languages
Python
97.2%
Shell
2.8%