Skip to content

Latest commit

 

History

History
274 lines (217 loc) · 4.18 KB

File metadata and controls

274 lines (217 loc) · 4.18 KB

API Documentation

REST API Endpoints

Base URL: http://localhost:8080

1. Create Document

Create a new collaborative document.

Endpoint: POST /api/documents

Request Body:

{
  "title": "My Document",
  "content": "Initial content"
}

Response: 201 Created

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "title": "My Document",
  "content": "Initial content",
  "createdAt": "2026-01-12T10:00:00Z",
  "updatedAt": "2026-01-12T10:00:00Z",
  "version": 1
}

Example:

curl -X POST http://localhost:8080/api/documents \
  -H "Content-Type: application/json" \
  -d '{"title":"My Document","content":"Hello World"}'

2. List Documents

Get all documents.

Endpoint: GET /api/documents

Response: 200 OK

[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "title": "My Document",
    "content": "Hello World",
    "createdAt": "2026-01-12T10:00:00Z",
    "updatedAt": "2026-01-12T10:00:00Z",
    "version": 1
  }
]

Example:

curl http://localhost:8080/api/documents

3. Get Document

Retrieve a specific document by ID.

Endpoint: GET /api/documents/{documentId}

Response: 200 OK

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "title": "My Document",
  "content": "Hello World",
  "createdAt": "2026-01-12T10:00:00Z",
  "updatedAt": "2026-01-12T10:00:00Z",
  "version": 1
}

Error Response: 404 Not Found

{
  "error": "Document not found"
}

Example:

curl http://localhost:8080/api/documents/550e8400-e29b-41d4-a716-446655440000

4. Update Document

Update an existing document.

Endpoint: PUT /api/documents/{documentId}

Request Body:

{
  "content": "Updated content"
}

Response: 200 OK

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "title": "My Document",
  "content": "Updated content",
  "createdAt": "2026-01-12T10:00:00Z",
  "updatedAt": "2026-01-12T10:05:00Z",
  "version": 2
}

Example:

curl -X PUT http://localhost:8080/api/documents/550e8400-e29b-41d4-a716-446655440000 \
  -H "Content-Type: application/json" \
  -d '{"content":"Updated content"}'

5. Delete Document

Delete a document.

Endpoint: DELETE /api/documents/{documentId}

Response: 204 No Content

Error Response: 404 Not Found

Example:

curl -X DELETE http://localhost:8080/api/documents/550e8400-e29b-41d4-a716-446655440000

6. Health Check

Check server health.

Endpoint: GET /health

Response: 200 OK

{
  "status": "healthy"
}

Example:

curl http://localhost:8080/health

QUIC Collaboration Protocol

Server: quic://localhost:4433

Connection Flow

1. Establish QUIC Connection

tlsConfig := &tls.Config{
    InsecureSkipVerify: true, // Only for development
    NextProtos:         []string{"collaborative-doc-quic"},
}

conn, err := quic.DialAddr("localhost:4433", tlsConfig, nil)

2. Open Stream

stream, err := conn.OpenStreamSync(context.Background())

3. Send Join Message

{
  "type": "join",
  "documentId": "550e8400-e29b-41d4-a716-446655440000",
  "clientId": "client-123"
}

4. Receive Init Message

{
  "type": "init",
  "document": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "title": "My Document",
    "content": "Hello World",
    "version": 1
  }
}

5. Send Operations

{
  "type": "operation",
  "operation": {
    "type": "insert",
    "position": 5,
    "text": " there",
    "version": 1,
    "clientId": "client-123"
  }
}

6. Receive Broadcast Operations

{
  "type": "operation",
  "operation": {
    "type": "insert",
    "position": 11,
    "text": "!",
    "version": 2,
    "clientId": "client-456"
  }
}

Operation Types

Insert Operation

{
  "type": "insert",
  "position": 10,
  "text": "Hello",
  "version": 1,
  "clientId": "client-123"
}

Delete Operation

{
  "type": "delete",
  "position": 5,
  "length": 3,
  "version": 2,
  "clientId": "client-123"
}

Error Messages

{
  "type": "error",
  "message": "Document not found"
}