REST API - Realtime#
Two transports:
- WebSocket - recommended. One connection, auto-reconnect, event recovery.
- SSE - legacy single-table stream.
Connect (WebSocket)#
POST /projects/{project_id}/realtime/connect?table=messages
X-AFRIBASE-API-Key: raf_live_...
Text{
"success": true,
"message": "Request was successful",
"data": {
"url": "http://localhost:8000",
"token": "eyJhbGciOiJIUzI1NiIs...",
"channel": "project:5c73dab0-...:messages",
"expires_at": "2026-10-04T23:58:25+03:00"
}
}
JSON- Open a WebSocket to
{url}/connection/websocket. - Send
{"id":1,"connect":{"token":"..."}}(the token grants the channel). - Receive pushes as
{"push":{"channel":"...","pub":{"data":{...}}}}.
Tokens are valid 24 hours and scoped to one channel.
SSE#
GET /projects/{project_id}/realtime/events?api_key=raf_live_...&table=orders&events=INSERT,UPDATE
Text| Param | Description |
|---|---|
api_key | Project API key (browsers use this since EventSource cannot set headers) |
token | Short-lived realtime token (10 min) |
table | Filter to one table |
events | Comma-separated: INSERT,UPDATE,DELETE |
The stream sends named SSE frames:
event: INSERT
data: {"id":"...","type":"INSERT","table":"orders","record":{...}}
TextEvent payload#
{
"id": "uuid",
"type": "INSERT",
"table": "messages",
"project_id": "5c73dab0-...",
"record": { },
"old_record": null,
"created_at": "2026-10-03T20:47:34Z"
}
JSONSettings#
| Endpoint | Method | Description |
|---|---|---|
/projects/{id}/realtime/settings | GET / PUT | Enable, broadcast flags |
/projects/{id}/realtime/channels | GET / POST / DELETE | Configured channels |
/projects/{id}/realtime/token | POST | Short-lived realtime token |
Recovery#
The the realtime server channel keeps the last 100 events (10 minutes) of history. WebSocket clients recover missed events automatically after a reconnect.