Wiki首页 / API文档
最后编辑者 未知用户
最后更新 2026年01月01日 23:41
浏览次数 13
编辑次数 0

API文档

概述

Wiki系统提供RESTful API接口,方便开发者集成和使用Wiki功能。

认证方式

JWT Token认证

所有API请求需要在Header中携带JWT Token:

Authorization: Bearer <your_jwt_token>

获取Token

POST /api/auth/login
Content-Type: application/json

{
    "username": "your_username",
    "password": "your_password"
}

响应:

{
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
    "token_type": "bearer",
    "expires_in": 3600
}

页面管理API

获取页面列表

GET /api/wiki/pages

响应:

{
    "pages": [
        {
            "id": 1,
            "title": "新手指南",
            "slug": "getting-started",
            "summary": "Wiki系统使用指南",
            "created_at": "2024-01-01T00:00:00",
            "updated_at": "2024-01-01T00:00:00",
            "view_count": 156
        }
    ],
    "total": 5,
    "page": 1,
    "per_page": 20
}

获取单个页面

GET /api/wiki/pages/{slug}

创建新页面

POST /api/wiki/pages
Content-Type: application/json

{
    "title": "新页面标题",
    "content": "页面内容",
    "summary": "页面摘要"
}

更新页面

PUT /api/wiki/pages/{slug}
Content-Type: application/json

{
    "title": "更新后的标题",
    "content": "更新后的内容",
    "summary": "更新后的摘要"
}

删除页面

DELETE /api/wiki/pages/{slug}

搜索API

搜索页面

GET /api/wiki/search?q={query}&category={category}&page={page}

参数: - q: 搜索关键词 - category: 页面类别(可选) - page: 页码(可选,默认1)

响应:

{
    "results": [
        {
            "id": 1,
            "title": "搜索结果标题",
            "slug": "search-result",
            "summary": "搜索结果摘要",
            "relevance": 0.95
        }
    ],
    "total": 10,
    "page": 1,
    "per_page": 10
}

历史记录API

获取页面历史

GET /api/wiki/pages/{slug}/history

获取特定版本

GET /api/wiki/pages/{slug}/history/{version}

回滚到特定版本

POST /api/wiki/pages/{slug}/history/{version}/revert

错误代码

代码 描述
200 成功
400 请求参数错误
401 未授权
403 禁止访问
404 页面不存在
409 编辑冲突
500 服务器内部错误

速率限制

  • 普通用户:60次/分钟
  • 认证用户:120次/分钟
  • 管理员:无限制

示例代码

Python示例

import requests

# 获取页面列表
response = requests.get('http://localhost:5501/api/wiki/pages')
pages = response.json()

# 创建新页面
headers = {'Authorization': 'Bearer your_token'}
data = {
    'title': '新页面',
    'content': '页面内容',
    'summary': '页面摘要'
}
response = requests.post('http://localhost:5501/api/wiki/pages', 
                        headers=headers, json=data)

JavaScript示例

// 获取页面列表
fetch('/api/wiki/pages')
    .then(response => response.json())
    .then(data => console.log(data));

// 创建新页面
fetch('/api/wiki/pages', {
    method: 'POST',
    headers: {
        'Authorization': 'Bearer your_token',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        title: '新页面',
        content: '页面内容',
        summary: '页面摘要'
    })
});