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