API 文档
基础信息
- 基础URL:
http://localhost:5000/api - 所有请求都需要在 Header 中包含
Authorization: Bearer <token> - 响应格式为 JSON
认证
用户注册
- URL:
/auth/register - Method:
POST - Content-Type:
application/json
请求体:
响应:
{
"message": "User registered successfully",
"user": {
"id": "integer",
"username": "string",
"email": "string"
}
}
用户登录
- URL:
/auth/login - Method:
POST - Content-Type:
application/json
请求体:
响应:
{
"access_token": "string",
"refresh_token": "string",
"user": {
"id": "integer",
"username": "string",
"email": "string"
}
}
文章
获取文章列表
- URL:
/articles - Method:
GET - Query Parameters:
page: 页码(默认:1)per_page: 每页数量(默认:10)category: 分类 IDtag: 标签 ID
响应:
{
"articles": [
{
"id": "integer",
"title": "string",
"content": "string",
"created_at": "datetime",
"updated_at": "datetime",
"author": {
"id": "integer",
"username": "string"
},
"category": {
"id": "integer",
"name": "string"
},
"tags": [
{
"id": "integer",
"name": "string"
}
]
}
],
"total": "integer",
"pages": "integer",
"current_page": "integer"
}
获取文章详情
- URL:
/articles/{id} - Method:
GET
响应:
{
"id": "integer",
"title": "string",
"content": "string",
"created_at": "datetime",
"updated_at": "datetime",
"author": {
"id": "integer",
"username": "string"
},
"category": {
"id": "integer",
"name": "string"
},
"tags": [
{
"id": "integer",
"name": "string"
}
],
"comments": [
{
"id": "integer",
"content": "string",
"created_at": "datetime",
"author": {
"id": "integer",
"username": "string"
}
}
]
}
创建文章
- URL:
/articles - Method:
POST - Content-Type:
application/json
请求体:
响应:
{
"message": "Article created successfully",
"article": {
"id": "integer",
"title": "string",
"content": "string",
"created_at": "datetime",
"updated_at": "datetime",
"author": {
"id": "integer",
"username": "string"
},
"category": {
"id": "integer",
"name": "string"
},
"tags": [
{
"id": "integer",
"name": "string"
}
]
}
}
分类
获取分类列表
- URL:
/categories - Method:
GET
响应:
创建分类
- URL:
/categories - Method:
POST - Content-Type:
application/json
请求体:
响应:
{
"message": "Category created successfully",
"category": {
"id": "integer",
"name": "string",
"description": "string"
}
}
标签
获取标签列表
- URL:
/tags - Method:
GET
响应:
创建标签
- URL:
/tags - Method:
POST - Content-Type:
application/json
请求体:
响应:
评论
获取文章评论
- URL:
/articles/{id}/comments - Method:
GET
响应:
{
"comments": [
{
"id": "integer",
"content": "string",
"created_at": "datetime",
"author": {
"id": "integer",
"username": "string"
}
}
]
}
创建评论
- URL:
/articles/{id}/comments - Method:
POST - Content-Type:
application/json
请求体:
响应:
{
"message": "Comment created successfully",
"comment": {
"id": "integer",
"content": "string",
"created_at": "datetime",
"author": {
"id": "integer",
"username": "string"
}
}
}
错误响应
所有错误响应都遵循以下格式:
常见错误代码: - 400: 请求参数错误 - 401: 未授权 - 403: 禁止访问 - 404: 资源不存在 - 500: 服务器内部错误