获取文章详情
根据文章 ID 或 Slug 获取单篇文章的详细信息。
接口信息
- 请求路径:
GET /api/articles/:id - 认证方式: 无需认证(公开接口)
- 内容类型:
application/json
路径参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | string/number | 是 | 文章 ID 或 Slug |
响应字段
| 字段名 | 类型 | 说明 |
|---|---|---|
| id | number | 文章 ID |
| title | string | 文章标题 |
| slug | string | URL 友好的标识符 |
| content | string | 文章内容(Markdown 格式) |
| excerpt | string | 文章摘要 |
| coverImage | string | 封面图片 URL |
| categoryId | number | 分类 ID |
| categoryName | string | 分类名称 |
| authorId | number | 作者 ID |
| authorName | string | 作者名称 |
| viewCount | number | 浏览次数 |
| likeCount | number | 点赞次数 |
| status | string | 状态:published/draft |
| createdAt | string | 创建时间 |
| updatedAt | string | 更新时间 |
请求示例
bash
# 使用 ID
curl http://localhost:3000/api/articles/1
# 使用 Slug
curl http://localhost:3000/api/articles/my-first-post响应示例
json
{
"success": true,
"data": {
"id": 1,
"title": "我的第一篇文章",
"slug": "my-first-post",
"content": "# 文章内容\n\n这里是文章的正文内容...",
"excerpt": "文章摘要",
"coverImage": "https://example.com/cover.jpg",
"categoryId": 1,
"categoryName": "技术分享",
"authorId": 1,
"authorName": "管理员",
"viewCount": 128,
"likeCount": 32,
"status": "published",
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2024-01-15T12:00:00.000Z"
}
}错误响应
| HTTP 状态码 | 说明 |
|---|---|
| 404 | 文章不存在 |
| 500 | 服务器错误 |
Slug 生成规则
- 文章创建时自动生成
- 基于标题转小写
- 空格和特殊字符替换为连字符
- 去除首尾连字符
- 多个连字符合并为一个