API 参考
API 概述
主公 提供基于 Hono 框架构建的 RESTful API,兼顾高性能和类型安全。
基础 URL:http://localhost:3000/api
身份验证
除非另有说明,所有 API 请求都需要身份验证。请在请求中携带会话令牌:
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:3000/api/spaces
接口
空间
列出空间
GET /api/spaces
响应:
{
"spaces": [
{
"id": "space_123",
"name": "My Workspace",
"description": "Team workspace",
"createdAt": "2024-01-15T10:30:00Z"
}
]
}
创建空间
POST /api/spaces
Content-Type: application/json
{
"name": "New Workspace",
"description": "Description here"
}
响应:
{
"space": {
"id": "space_124",
"name": "New Workspace",
"description": "Description here",
"createdAt": "2024-01-15T11:00:00Z"
}
}
获取空间
GET /api/spaces/:spaceId
更新空间
PATCH /api/spaces/:spaceId
Content-Type: application/json
{
"name": "Updated Name",
"description": "Updated description"
}
删除空间
DELETE /api/spaces/:spaceId
节点
列出空间中的节点
GET /api/spaces/:spaceId/nodes
查询参数:
type- 按节点类型筛选(文档、文件夹等)parentId- 按父节点 ID 筛选limit- 结果数量(默认:50)offset- 分页偏移量
创建节点
POST /api/spaces/:spaceId/nodes
Content-Type: application/json
{
"type": "document",
"name": "Meeting Notes",
"parentId": "node_parent_123",
"content": {
"type": "doc",
"content": []
}
}
获取节点
GET /api/nodes/:nodeId
更新节点
PATCH /api/nodes/:nodeId
Content-Type: application/json
{
"name": "Updated Name",
"content": { /* updated content */ }
}
删除节点
DELETE /api/nodes/:nodeId
成员
列出空间成员
GET /api/spaces/:spaceId/members
响应:
{
"members": [
{
"id": "member_123",
"userId": "user_456",
"role": "admin",
"user": {
"name": "John Doe",
"email": "john@example.com"
}
}
]
}
添加成员
POST /api/spaces/:spaceId/members
Content-Type: application/json
{
"email": "newmember@example.com",
"role": "member"
}
更新成员角色
PATCH /api/spaces/:spaceId/members/:memberId
Content-Type: application/json
{
"role": "admin"
}
移除成员
DELETE /api/spaces/:spaceId/members/:memberId
错误响应
所有错误都遵循以下格式:
{
"error": "Error message",
"code": "ERROR_CODE",
"details": {}
}
常见错误码
UNAUTHORIZED(401)- 缺少身份验证信息或信息无效FORBIDDEN(403)- 权限不足NOT_FOUND(404)- 资源不存在VALIDATION_ERROR(400)- 请求数据无效INTERNAL_ERROR(500)- 服务器错误
速率限制
API 请求限制为:
- 已验证用户:每小时 1000 次请求
- 未验证用户:每小时 100 次请求
速率限制响应头:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640000000
Webhook
配置 Webhook 以接收实时更新:
POST /api/webhooks
Content-Type: application/json
{
"url": "https://your-app.com/webhook",
"events": ["space.created", "node.updated"]
}
Webhook 事件
space.createdspace.updatedspace.deletednode.creatednode.updatednode.deletedmember.addedmember.removed