PreviewRustaBase OSS is in public preview. Build on managed PostgreSQL with APIs, authentication, storage, realtime, and server-side functions.Read the product direction

APIs and SDKs

Realtime subscriptions

Subscribe to record changes over server-sent events. The same access rules that protect a read also protect what a subscriber receives.

How it works

  1. The client opens an event stream at GET /api/v1/realtime.
  2. The server sends a connect event carrying the clientId for this stream.
  3. The client posts the topics it wants to POST /api/v1/realtime with that clientId.
  4. Matching create, update, and delete events arrive on the open stream.

Realtime uses server-sent events, not WebSockets. Any HTTP client that can read a stream can subscribe.

Subscribe with an SDK

// every record in the table
const stop = await rb.from("posts").subscribe("*", ({ action, record }) => {
  console.log(action, record); // create | update | delete
});

// a single record
await rb.from("posts").subscribe("k93jf0s1p2a7b4c", (e) => {
  console.log(e.record);
});

// stop listening
await stop(); // or: await rb.from("posts").unsubscribe("*");

Subscribe over raw HTTP

# 1. open the stream and read the clientId from the first event
curl -N $PROJECT_URL/api/v1/realtime

# 2. from another process, register the topics for that client
curl -X POST $PROJECT_URL/api/v1/realtime \
  -H "Content-Type: application/json" \
  -H "Authorization: $TOKEN" \
  -d '{"clientId":"the-id-from-the-connect-event","subscriptions":["posts"]}'

Production guidance

  • Subscribe to the narrowest topic your screen needs, not the whole table.
  • Unsubscribe when a view unmounts so streams are not left open.
  • Treat realtime as a live update channel, and the REST API as the source of truth on first load.
  • Re-authenticate and resubscribe after a session refresh.

JavaScript and TypeScript SDK

Found something wrong on this page?

Fix it yourself. The link below opens this file in GitHub's editor and forks the repository for you if you need one, and your change becomes a pull request without leaving the browser.