接口说明:获取随机文章
基本信息
- 请求方式:
GET
- 请求路径:
/randompost
- 功能描述:从文章库中随机返回指定数量的文章信息,可用于友链朋友圈的「随机文章推荐」。
请求参数
参数名 | 类型 | 位置 | 必填 | 说明 | 默认值 | 最小值 | 最大值 |
---|---|---|---|---|---|---|---|
num | integer | query | 否 | 返回的文章数量 | 1 | 1 | 100 |
响应参数
成功响应 (200)
- 说明:成功返回随机文章。
- 返回格式:
application/json
- 示例(返回单篇文章):
json
[
{
"title": "利用 Webhook 实现博客自动部署到服务器并通过飞书通知",
"created": "2025-07-05",
"updated": "2025-07-05",
"link": "https://xaoxuu.com/blog/20250705/",
"rule": "feed",
"author": "xaoxuu",
"avatar": "https://bu.dusays.com/2021/09/24/2f74810ceb3d3.png",
"createdAt": "2025-07-31 20:09:28"
}
]
失败响应
400 参数错误
- 说明:
rule
参数错误,应为'created'
或'updated'
。 - 示例:
json
{
"message": "rule error, please use 'created'/'updated'"
}
404 未找到文章
- 说明:数据库中未匹配到文章数据。
- 示例:
json
{
"message": "not found"
}
422 验证错误
- 说明:请求参数验证失败。
- 示例:
json
{
"detail": [
{
"loc": ["string", 0],
"msg": "string",
"type": "string"
}
]
}
使用说明
- 默认返回 1 篇随机文章,支持批量返回,最多 100 篇。
- 返回结果包含文章的
标题
、发布时间
、更新时间
、文章链接
、作者
、头像
等信息。 - 可用于前端展示「随机文章推荐」或「一键发现文章」功能。