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
  1. Open a WebSocket to {url}/connection/websocket.
  2. Send {"id":1,"connect":{"token":"..."}} (the token grants the channel).
  3. 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
ParamDescription
api_keyProject API key (browsers use this since EventSource cannot set headers)
tokenShort-lived realtime token (10 min)
tableFilter to one table
eventsComma-separated: INSERT,UPDATE,DELETE

The stream sends named SSE frames:

event: INSERT
data: {"id":"...","type":"INSERT","table":"orders","record":{...}}
Text

Event payload#

{
  "id": "uuid",
  "type": "INSERT",
  "table": "messages",
  "project_id": "5c73dab0-...",
  "record": { },
  "old_record": null,
  "created_at": "2026-10-03T20:47:34Z"
}
JSON

Settings#

EndpointMethodDescription
/projects/{id}/realtime/settingsGET / PUTEnable, broadcast flags
/projects/{id}/realtime/channelsGET / POST / DELETEConfigured channels
/projects/{id}/realtime/tokenPOSTShort-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.