1# API Routes
2
3JSON API endpoints for frontend/backend communication.
4
5## Separation of Concerns
6
7API routes handle:
8- JSON request/response formatting
9- HTTP status code management
11- Error response standardization
12
13API routes delegate business logic to controllers and return clean JSON responses.
14
15## Endpoints
16
17### GET /api/health
18
19**Purpose**: System health check endpoint
32**HTTP Status**: Always 200
33
34### POST /api/viewing
35
36**Purpose**: Update page viewing status in blob storage for real-time tracking with immediate Notion sync
41 pageId: string, // Notion page UUID
42 viewing: boolean, // true when actively viewing, false when leaving
43 tabVisible: boolean // Page Visibility API state
44}
45```
92```
93
94### GET /api/viewing/:id
95
96**Purpose**: Get current viewing status for a page
125**Error Responses**: Same pattern as other endpoints
126
127### GET /api/viewing/:id/stats
128
129**Purpose**: Get viewing analytics/statistics for a page
148```
149
150### GET /api/demo/:id/properties
151
152**Purpose**: Get Notion page properties (filtered for UI consumption)
198{
199 error: "Failed to fetch page data",
200 details: "Notion API error message"
201}
202```
203
204### GET /api/demo/:id
205
206**Purpose**: Get complete Notion page with content blocks
251## Error Handling Pattern
252
253All API routes follow consistent error handling:
254
255```typescript
269## Data Filtering
270
271API routes return filtered data for UI consumption:
272- **Button properties removed**: Notion button properties are filtered out to prevent UI confusion
273- **Raw Notion format**: Other properties maintain their original Notion API structure
274- **Complete hierarchy**: Block content includes full nested structure with children
275
278```bash
279# Get page properties only
280curl https://your-val.web.val.run/api/demo/abc123/properties
281
282# Get complete page with content
283curl https://your-val.web.val.run/api/demo/abc123
284
285# Health check
286curl https://your-val.web.val.run/api/health
287```