|
|
||
|---|---|---|
| app | ||
| src | ||
| tests | ||
| .gitignore | ||
| README.md | ||
| events.ndjson | ||
| pom.xml | ||
| requirements.txt | ||
README.md
单体示例工程
一个基于 FastAPI 的简单待办事项(Todo)管理服务,使用内存假数据存储。
功能
- 获取所有待办事项列表
- 根据 ID 获取单个待办事项
- 创建新的待办事项
- 更新待办事项
- 删除待办事项
安装依赖
cd codegen-runs/codegen_a2cef5070965479b93c5b3c07d4c8216
pip install -r requirements.txt
启动服务
uvicorn app.main:app --reload --port 8000
访问 http://127.0.0.1:8000/docs 查看自动生成的 API 文档(Swagger UI)。
运行测试
cd codegen-runs/codegen_a2cef5070965479b93c5b3c07d4c8216
pytest tests/ -v
快速验证
启动服务后,在另一个终端执行:
# 获取所有待办事项
curl http://127.0.0.1:8000/todos
# 创建新待办事项
curl -X POST http://127.0.0.1:8000/todos \
-H "Content-Type: application/json" \
-d '{"title": "学习 FastAPI", "completed": false}'