1.3 KiB
1.3 KiB
Todo Manager - 任务管理器示例工程
基于 FastAPI 的单体示例工程,使用内存假数据完成任务的增删改查核心流程。
技术栈
- Python 3.11+
- FastAPI (Web 框架)
- Pydantic (数据校验)
- Uvicorn (ASGI 服务器)
- Pytest + HTTPX (测试)
安装依赖
cd codegen-runs/codegen_8a0046bfd6e148b3ab096039e55d5f72
pip install -r requirements.txt
启动服务
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
服务启动后访问:
- API 文档: http://127.0.0.1:8000/docs
- 替代文档: http://127.0.0.1:8000/redoc
API 接口
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /api/todos | 获取所有任务 |
| GET | /api/todos/{id} | 根据 ID 获取任务 |
| POST | /api/todos | 创建新任务 |
| PUT | /api/todos/{id} | 更新任务 |
| DELETE | /api/todos/{id} | 删除任务 |
请求/响应示例
创建任务:
curl -X POST "http://127.0.0.1:8000/api/todos" \
-H "Content-Type: application/json" \
-d '{"title": "学习 FastAPI", "description": "完成 Todo 示例项目"}'
获取所有任务:
curl "http://127.0.0.1:8000/api/todos"
运行测试
cd codegen-runs/codegen_8a0046bfd6e148b3ab096039e55d5f72
pytest tests/ -v