Skip to main content

文章管理 API

文章管理相关的 API 接口,包括文章的创建、查询、更新和删除操作。

获取文章列表

请求

GET /v1/articles
Authorization: Bearer {your_access_token}

查询参数

参数类型必填描述
pageinteger页码,默认 1
page_sizeinteger每页数量,默认 20
keywordstring搜索关键词
statusstring文章状态:draft, published
author_idstring作者 ID

请求示例

curl -X GET "https://api.example.com/v1/articles?page=1&status=published" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

响应示例

{
"code": 200,
"message": "success",
"data": {
"total": 50,
"page": 1,
"page_size": 20,
"items": [
{
"id": "article_123",
"title": "示例文章标题",
"summary": "文章摘要...",
"author": {
"id": "user_123",
"username": "john_doe"
},
"status": "published",
"views": 1000,
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
]
},
"timestamp": 1640995200000
}

获取文章详情

请求

GET /v1/articles/{article_id}
Authorization: Bearer {your_access_token}

请求示例

curl -X GET https://api.example.com/v1/articles/article_123 \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

响应示例

{
"code": 200,
"message": "success",
"data": {
"id": "article_123",
"title": "示例文章标题",
"content": "文章完整内容...",
"summary": "文章摘要...",
"author": {
"id": "user_123",
"username": "john_doe",
"avatar": "https://example.com/avatars/user_123.jpg"
},
"tags": ["技术", "教程"],
"status": "published",
"views": 1000,
"likes": 50,
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
},
"timestamp": 1640995200000
}

创建文章

请求

POST /v1/articles
Authorization: Bearer {your_access_token}
Content-Type: application/json

请求参数

参数类型必填描述
titlestring文章标题
contentstring文章内容
summarystring文章摘要
tagsarray标签数组
statusstring状态,默认 draft

请求示例

curl -X POST https://api.example.com/v1/articles \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "新文章标题",
"content": "文章内容...",
"summary": "文章摘要",
"tags": ["技术", "教程"],
"status": "published"
}'

更新文章

请求

PUT /v1/articles/{article_id}
Authorization: Bearer {your_access_token}
Content-Type: application/json

请求示例

curl -X PUT https://api.example.com/v1/articles/article_123 \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "更新后的标题",
"content": "更新后的内容..."
}'

删除文章

请求

DELETE /v1/articles/{article_id}
Authorization: Bearer {your_access_token}

请求示例

curl -X DELETE https://api.example.com/v1/articles/article_123 \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

下一步