API 文档
基本信息
- Base URL:
http://localhost:8000/api/v1 - 认证方式: JWT Token(Bearer Auth)
- 响应格式: JSON
统一响应格式
成功响应
{
"code": 200,
"message": "success",
"data": { ... }
}
错误响应
{
"code": 400,
"message": "error description",
"data": null
}
API 端点
1. 用户认证
1.1 用户注册
POST /auth/register
请求体:
{
"username": "string (required, 3-20 chars)",
"email": "string (required, valid email)",
"password": "string (required, 6-50 chars)"
}
响应: 用户信息 + Token
1.2 用户登录
POST /auth/login
请求体:
{
"username": "string",
"password": "string"
}
响应:
{
"code": 200,
"data": {
"token": "jwt_token",
"user": {
"id": 1,
"username": "user1",
"email": "user1@example.com"
}
}
}
2. 待办事项
2.1 获取待办列表
GET /todos
查询参数:
| 参数 | 类型 | 说明 |
|---|---|---|
| status | string | 筛选状态:pending/completed |
| category_id | int | 筛选分类 |
| page | int | 页码,默认1 |
| limit | int | 每页数量,默认20 |
响应:
{
"code": 200,
"data": {
"items": [
{
"id": 1,
"title": "Task title",
"description": "Task description",
"status": "pending",
"priority": "high",
"category_id": 1,
"due_date": "2024-05-20",
"created_at": "2024-05-01T10:00:00Z",
"updated_at": "2024-05-01T10:00:00Z"
}
],
"total": 100,
"page": 1,
"limit": 20
}
}
2.2 创建待办事项
POST /todos
请求体:
{
"title": "string (required, 1-100 chars)",
"description": "string (optional, 0-500 chars)",
"priority": "string (optional: low/medium/high)",
"category_id": "int (optional)",
"due_date": "string (optional, YYYY-MM-DD)"
}
2.3 更新待办事项
PUT /todos/{id}
请求体: 同创建
2.4 删除待办事项
DELETE /todos/{id}
2.5 更改待办状态
PATCH /todos/{id}/status
请求体:
{
"status": "completed"
}
3. 分类管理
3.1 获取分类列表
GET /categories
响应:
{
"code": 200,
"data": [
{
"id": 1,
"name": "工作",
"color": "#FF5733"
}
]
}
3.2 创建分类
POST /categories
请求体:
{
"name": "string (required, 1-30 chars)",
"color": "string (optional, hex color)"
}
3.3 更新分类
PUT /categories/{id}
3.4 删除分类
DELETE /categories/{id}
错误码
| 错误码 | 说明 |
|---|---|
| 400 | 请求参数错误 |
| 401 | 未认证 |
| 403 | 无权限 |
| 404 | 资源不存在 |
| 409 | 资源冲突 |
| 500 | 服务器错误 |
接口变更日志
| 版本 | 日期 | 变更 |
|---|---|---|
| v1.0 | 2024-05-01 | 初始版本 |
| v1.1 | 2024-05-15 | 增加 PATCH /todos/{id}/status |