Skip to content

获取文章详情

根据文章 ID 或 Slug 获取单篇文章的详细信息。

接口信息

  • 请求路径: GET /api/articles/:id
  • 认证方式: 无需认证(公开接口)
  • 内容类型: application/json

路径参数

参数名类型必填说明
idstring/number文章 ID 或 Slug

响应字段

字段名类型说明
idnumber文章 ID
titlestring文章标题
slugstringURL 友好的标识符
contentstring文章内容(Markdown 格式)
excerptstring文章摘要
coverImagestring封面图片 URL
categoryIdnumber分类 ID
categoryNamestring分类名称
authorIdnumber作者 ID
authorNamestring作者名称
viewCountnumber浏览次数
likeCountnumber点赞次数
statusstring状态:published/draft
createdAtstring创建时间
updatedAtstring更新时间

请求示例

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 生成规则

  • 文章创建时自动生成
  • 基于标题转小写
  • 空格和特殊字符替换为连字符
  • 去除首尾连字符
  • 多个连字符合并为一个

相关接口