文章列表接口
接口说明
获取博客文章列表,支持分页查询和分类筛选。返回经过处理的文章预览信息,包括文章标题、分类、发布日期等基本信息。
- 接口URL:
/api/articles/index
- 请求方法:
POST
- 权限要求: 支持匿名访问,登录用户可查看更多信息
请求参数
参数名 | 类型 | 必填 | 说明 | 示例值 |
---|---|---|---|---|
page_numer | number | 否 | 页码,从1开始。不传则返回所有数据 | 1 |
page_size | number | 否 | 每页条数。不传则返回所有数据 | 10 |
classify_path | string | 否 | 分类路径,用于筛选特定分类的文章 | "tech" |
响应结构
typescript
interface Response {
code: number; // 状态码
message: string; // 响应消息
data: {
list: Article[]; // 文章列表
total: number; // 总条数
}
}
interface Article {
article_id: number; // 文章ID
article_title: string; // 文章标题
article_date: string; // 发布日期
article_text: string; // 文章内容(预览,最多60字)
article_title_image: string; // 标题图片
article_views: number; // 浏览量
article_likes: number; // 点赞数
article_comments: number; // 评论数
article_private: number; // 是否私密
has_password: boolean; // 是否需要密码访问
}
响应示例
json
{
"code": 0,
"message": "success",
"data": {
"list": [
{
"article_id": 1,
"article_title": "示例文章",
"article_date": "2024-01-01",
"article_text": "这是一篇示例文章的内容预览...",
"article_title_image": "https://example.com/image.jpg",
"article_views": 100,
"article_likes": 50,
"article_comments": 10,
"article_private": 0,
"has_password": false
}
],
"total": 1
}
}
特殊说明
文章内容处理
- 返回的文章内容(
article_text
)会被截断至最多60个字符,超出部分用...替代 - 私密文章(
article_private=1
)不会在列表中显示 - 加密文章的内容会被过滤,但会标记
has_password=true
分页说明
- 当不传入
page_numer
和page_size
时,将返回所有符合条件的文章 - 分页参数必须同时提供,否则视为不分页
- 页码从1开始计数
排序规则
- 文章默认按发布日期(
article_date
)降序排列 - 暂不支持自定义排序
错误码说明
错误码 | 说明 | 处理建议 |
---|---|---|
0 | 成功 | - |
500 | 服务器错误 | 请联系管理员 |
调用示例
基础调用
typescript
const response = await fetch('/api/articles/index', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
page_numer: 1,
page_size: 10
})
});
带分类筛选的调用
typescript
const response = await fetch('/api/articles/index', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
page_numer: 1,
page_size: 10,
classify_path: 'tech'
})
});