Sify Gist API 文档
简介
Sify Gist 提供了一个完整的 RESTful API,用于创建、读取、更新和删除代码片段(Gist)。
认证
大多数 API 端点需要用户认证。认证通过 JWT 令牌实现,需要在请求头中包含 Authorization: Bearer `token`。
API 端点
获取所有 Gists
GET/api/gists
描述: 获取所有公共 Gists,按创建时间倒序排列。
参数:
limit(可选): 限制返回结果数量,默认为 50offset(可选): 偏移量,默认为 0
响应示例:
[
{
"id": "abc123",
"title": "Hello World 示例",
"description": "一个简单的 Hello World 程序",
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z",
"files": [
{
"filename": "hello.js",
"content": "console.log('Hello World');",
"language": "javascript"
}
]
}
]获取特定 Gist
GET/api/gists/{id}
描述: 获取指定 ID 的 Gist 信息。
参数:
id(必需): Gist 的唯一标识符
响应示例:
{
"id": "abc123",
"title": "Hello World 示例",
"description": "一个简单的 Hello World 程序",
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z",
"files": [
{
"filename": "hello.js",
"content": "console.log('Hello World');",
"language": "javascript"
}
]
}创建新 Gist
POST/api/gists
描述: 创建一个新的 Gist。
请求体:
{
"title": "My New Gist",
"description": "A description for my gist",
"files": [
{
"filename": "example.js",
"content": "console.log('Hello');",
"language": "javascript"
}
]
}响应示例:
{
"id": "newId123",
"title": "My New Gist",
"description": "A description for my gist",
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z",
"files": [
{
"filename": "example.js",
"content": "console.log('Hello');",
"language": "javascript"
}
]
}获取 Gist 版本历史
GET/api/gists/{id}/versions
描述: 获取指定 Gist 的所有版本历史。
参数:
id(必需): Gist 的唯一标识符
响应示例:
[
{
"id": 1,
"gist_id": "abc123",
"version_number": 1,
"created_at": "2023-01-01T00:00:00Z",
"files": [
{
"filename": "hello.js",
"content": "console.log('Hello World');",
"language": "javascript"
}
]
}
]获取 Gist 原始文件
GET/api/gists/{id}/raw/{filename}
描述: 获取指定 Gist 中特定文件的原始内容。
参数:
id(必需): Gist 的唯一标识符filename(必需): 文件名
导出 Gist 为 ZIP
GET/api/gists/{id}/export
描述: 将指定 Gist 的所有文件打包为 ZIP 文件下载。
参数:
id(必需): Gist 的唯一标识符
错误处理
API 使用标准 HTTP 状态码来表示请求结果:
200 OK- 请求成功201 Created- 资源创建成功400 Bad Request- 请求格式错误或参数缺失401 Unauthorized- 未提供有效认证信息404 Not Found- 请求的资源不存在500 Internal Server Error- 服务器内部错误