The Realtime API is implemented via Server-Sent Events (SSE). Generally, it consists of 2 operations:

  • establish SSE connection
  • set client subscriptions

SSE events are sent for create, update and delete record operations.

You could subscribe to a single record or to an entire collection.

When you subscribe to a single record, the collection's ViewRule will be used to determine whether the subscriber has access to receive the event message.

When you subscribe to an entire collection, the collection's ListRule will be used to determine whether the subscriber has access to receive the event message.

All of this is seamlessly handled by the SDKs using just the subscribe and unsubscribe methods:

import PocketBase from 'pocketbase'; const client = new PocketBase('http://127.0.0.1:8090'); // (Optionally) authenticate client.users.authViaEmail('test@example.com', '123456'); // Subscribe to changes in any record from the "demo" collection client.realtime.subscribe('demo', function (e) { console.log(e.record); }); // Subscribe to changes in a single "demo" collection record client.realtime.subscribe('demo/YOUR_RECORD_ID', function (e) { console.log(e.record); }); // Unsubscribe client.realtime.unsubscribe() // remove all subscriptions client.realtime.unsubscribe('demo') // remove the collection subscription client.realtime.unsubscribe('demo/YOUR_RECORD_ID') // remove the record subscription
import 'package:pocketbase/pocketbase.dart'; final client = PocketBase('http://127.0.0.1:8090'); // (Optionally) authenticate client.users.authViaEmail('test@example.com', '123456'); // Subscribe to changes in any record from the "demo" collection client.realtime.subscribe('demo', (e) { print(e.record); }); // Subscribe to changes in a single "demo" collection record client.realtime.subscribe('demo/YOUR_RECORD_ID', (e) { print(e.record); }); // Unsubscribe client.realtime.unsubscribe() // remove all subscriptions client.realtime.unsubscribe('demo') // remove the collection subscription client.realtime.unsubscribe('demo/YOUR_RECORD_ID') // remove the record subscription

API Endpoints

Connect
Set subscriptions