获取项目列表
获取所有已发布的项目的列表,支持分页和筛选。
接口信息
- 请求路径:
GET /api/projects - 认证方式: 无需认证(公开接口)
- 内容类型:
application/json
查询参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | number | 否 | 页码,默认 1 |
| limit | number | 否 | 每页数量,默认 10 |
| category | number | 否 | 分类 ID 筛选 |
| status | string | 否 | 状态筛选:published/draft |
响应字段
| 字段名 | 类型 | 说明 |
|---|---|---|
| data | array | 项目列表 |
| total | number | 总记录数 |
| page | number | 当前页码 |
| limit | number | 每页数量 |
| totalPages | number | 总页数 |
项目字段
| 字段名 | 类型 | 说明 |
|---|---|---|
| id | number | 项目 ID |
| title | string | 项目标题 |
| description | string | 项目描述 |
| coverImage | string | 封面图片 URL |
| demoUrl | string | 演示链接 |
| repoUrl | string | 代码仓库链接 |
| techStack | array | 技术栈标签 |
| likeCount | number | 点赞次数 |
| viewCount | number | 浏览次数 |
| status | string | 状态:published/draft |
| createdAt | string | 创建时间 |
请求示例
bash
# 获取第一页
curl http://localhost:3000/api/projects
# 获取第 2 页,每页 20 条
curl http://localhost:3000/api/projects?page=2&limit=20
# 筛选分类
curl http://localhost:3000/api/projects?category=1响应示例
json
{
"success": true,
"data": [
{
"id": 1,
"title": "个人博客系统",
"description": "基于 Nuxt.js 3 的现代化博客系统",
"coverImage": "https://example.com/project1.jpg",
"demoUrl": "https://demo.example.com",
"repoUrl": "https://github.com/user/blog",
"techStack": ["Nuxt.js", "TypeScript", "Tailwind CSS"],
"likeCount": 45,
"viewCount": 230,
"status": "published",
"createdAt": "2024-01-15T10:00:00.000Z"
}
],
"total": 100,
"page": 1,
"limit": 10,
"totalPages": 10
}错误响应
| HTTP 状态码 | 说明 |
|---|---|
| 400 | 参数错误 |
| 500 | 服务器错误 |