- Base URL:
http://localhost:3000/api - 认证方式: Bearer Token (JWT)
- Content-Type:
application/json
POST /auth/register请求体:
{
"email": "user@example.com",
"password": "password123"
}响应:
{
"success": true,
"data": {
"user": {
"id": 1,
"email": "user@example.com",
"createdAt": "2025-06-21T10:00:00.000Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}POST /auth/login请求体:
{
"email": "user@example.com",
"password": "password123",
"rememberMe": false
}响应: 同注册接口
GET /auth/verify
Authorization: Bearer <token>响应:
{
"success": true,
"data": {
"valid": true,
"user": {
"id": 1,
"email": "user@example.com"
}
}
}GET /projects
Authorization: Bearer <token>响应:
{
"success": true,
"data": [
{
"id": 1,
"userId": 1,
"name": "收件箱",
"isInbox": true,
"createdAt": "2025-06-21T10:00:00.000Z",
"taskCount": 5,
"uncompletedTaskCount": 3
}
]
}POST /projects
Authorization: Bearer <token>请求体:
{
"name": "工作项目"
}PATCH /projects/:id
Authorization: Bearer <token>请求体:
{
"name": "新项目名称"
}DELETE /projects/:id
Authorization: Bearer <token>GET /tasks?projectId=1&status=pending&page=1&limit=20
Authorization: Bearer <token>查询参数:
projectId: 项目IDstatus: 任务状态 (pending,completed)priority: 优先级 (low,medium,high)dueDate: 截止日期 (YYYY-MM-DD)page: 页码limit: 每页数量sortBy: 排序字段 (createdAt,dueDate,priority,sortOrder)sortOrder: 排序方向 (asc,desc)
响应:
{
"success": true,
"data": {
"data": [
{
"id": 1,
"userId": 1,
"projectId": 1,
"title": "完成项目文档",
"description": "编写API文档和部署指南",
"status": "pending",
"priority": "high",
"dueDate": "2025-06-25",
"sortOrder": 1,
"createdAt": "2025-06-21T10:00:00.000Z",
"updatedAt": "2025-06-21T10:00:00.000Z",
"project": {
"id": 1,
"name": "收件箱",
"isInbox": true
}
}
],
"total": 10,
"page": 1,
"limit": 20,
"totalPages": 1
}
}POST /tasks
Authorization: Bearer <token>请求体:
{
"projectId": 1,
"title": "新任务",
"description": "任务描述",
"priority": "medium",
"dueDate": "2025-06-25"
}PATCH /tasks/:id
Authorization: Bearer <token>请求体:
{
"title": "更新的任务标题",
"status": "completed",
"priority": "high",
"dueDate": "2025-06-26"
}DELETE /tasks/:id
Authorization: Bearer <token>GET /tasks/today
Authorization: Bearer <token>GET /tasks/upcoming
Authorization: Bearer <token>POST /tasks/reorder
Authorization: Bearer <token>请求体:
{
"tasks": [
{
"id": 1,
"sortOrder": 1
},
{
"id": 2,
"sortOrder": 2
}
]
}所有错误响应都遵循以下格式:
{
"success": false,
"statusCode": 400,
"timestamp": "2025-06-21T10:00:00.000Z",
"path": "/api/tasks",
"method": "POST",
"message": "任务标题不能为空"
}400 Bad Request: 请求参数错误401 Unauthorized: 未认证或token无效403 Forbidden: 权限不足404 Not Found: 资源不存在409 Conflict: 资源冲突(如邮箱已存在)422 Unprocessable Entity: 数据验证失败500 Internal Server Error: 服务器内部错误
interface User {
id: number
email: string
createdAt: string
}interface Project {
id: number
userId: number
name: string
isInbox: boolean
createdAt: string
taskCount?: number
uncompletedTaskCount?: number
}interface Task {
id: number
userId: number
projectId: number
title: string
description?: string
status: 'pending' | 'completed'
priority: 'low' | 'medium' | 'high'
dueDate?: string
sortOrder: number
createdAt: string
updatedAt: string
project?: Project
}- 任务标题最大长度: 255字符
- 任务描述最大长度: 2000字符
- 项目名称最大长度: 100字符
- 每分钟API请求限制: 100次
- 分页最大限制: 100条/页
// 登录
const response = await fetch('/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'user@example.com',
password: 'password123'
})
})
const { data } = await response.json()
const token = data.token
// 获取任务列表
const tasksResponse = await fetch('/api/tasks?projectId=1', {
headers: {
'Authorization': `Bearer ${token}`
}
})
const tasks = await tasksResponse.json()# 登录
curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"password123"}'
# 获取任务列表
curl -X GET http://localhost:3000/api/tasks \
-H "Authorization: Bearer <token>"
# 创建任务
curl -X POST http://localhost:3000/api/tasks \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"projectId":1,"title":"新任务","priority":"medium"}'