主公 Sign in

API Reference

API Overview

主公 provides a RESTful API built with Hono framework, offering high performance and type safety.

Base URL: http://localhost:3000/api

Authentication

All API requests require authentication unless otherwise noted. Include the session token in your requests:

curl -H "Authorization: Bearer YOUR_TOKEN" \
  http://localhost:3000/api/spaces

Endpoints

Spaces

List Spaces

GET /api/spaces

Response:

{
  "spaces": [
    {
      "id": "space_123",
      "name": "My Workspace",
      "description": "Team workspace",
      "createdAt": "2024-01-15T10:30:00Z"
    }
  ]
}

Create Space

POST /api/spaces
Content-Type: application/json

{
  "name": "New Workspace",
  "description": "Description here"
}

Response:

{
  "space": {
    "id": "space_124",
    "name": "New Workspace",
    "description": "Description here",
    "createdAt": "2024-01-15T11:00:00Z"
  }
}

Get Space

GET /api/spaces/:spaceId

Update Space

PATCH /api/spaces/:spaceId
Content-Type: application/json

{
  "name": "Updated Name",
  "description": "Updated description"
}

Delete Space

DELETE /api/spaces/:spaceId

Nodes

List Nodes in Space

GET /api/spaces/:spaceId/nodes

Query Parameters:

  • type - Filter by node type (document, folder, etc.)
  • parentId - Filter by parent node ID
  • limit - Number of results (default: 50)
  • offset - Pagination offset

Create Node

POST /api/spaces/:spaceId/nodes
Content-Type: application/json

{
  "type": "document",
  "name": "Meeting Notes",
  "parentId": "node_parent_123",
  "content": {
    "type": "doc",
    "content": []
  }
}

Get Node

GET /api/nodes/:nodeId

Update Node

PATCH /api/nodes/:nodeId
Content-Type: application/json

{
  "name": "Updated Name",
  "content": { /* updated content */ }
}

Delete Node

DELETE /api/nodes/:nodeId

Members

List Space Members

GET /api/spaces/:spaceId/members

Response:

{
  "members": [
    {
      "id": "member_123",
      "userId": "user_456",
      "role": "admin",
      "user": {
        "name": "John Doe",
        "email": "john@example.com"
      }
    }
  ]
}

Add Member

POST /api/spaces/:spaceId/members
Content-Type: application/json

{
  "email": "newmember@example.com",
  "role": "member"
}

Update Member Role

PATCH /api/spaces/:spaceId/members/:memberId
Content-Type: application/json

{
  "role": "admin"
}

Remove Member

DELETE /api/spaces/:spaceId/members/:memberId

Error Responses

All errors follow this format:

{
  "error": "Error message",
  "code": "ERROR_CODE",
  "details": {}
}

Common Error Codes

  • UNAUTHORIZED (401) - Missing or invalid authentication
  • FORBIDDEN (403) - Insufficient permissions
  • NOT_FOUND (404) - Resource not found
  • VALIDATION_ERROR (400) - Invalid request data
  • INTERNAL_ERROR (500) - Server error

Rate Limiting

API requests are limited to:

  • Authenticated users: 1000 requests per hour
  • Unauthenticated: 100 requests per hour

Rate limit headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640000000

Webhooks

Configure webhooks to receive real-time updates:

POST /api/webhooks
Content-Type: application/json

{
  "url": "https://your-app.com/webhook",
  "events": ["space.created", "node.updated"]
}

Webhook Events

  • space.created
  • space.updated
  • space.deleted
  • node.created
  • node.updated
  • node.deleted
  • member.added
  • member.removed

Next Steps