Integrate Frontend
Realtime
Live data subscriptions for real-time updates.
QUESTPIE supports real-time data subscriptions. The client receives live updates when records change.
Transport
Realtime uses POST /realtime as a multiplexed endpoint. The client maintains a persistent connection and receives events for subscribed channels.
Client Subscription
import { client } from "@/lib/client";
// Subscribe to collection changes
client.realtime.on("collections:appointments:*", (event) => {
console.log(event.type); // "create", "update", "delete"
console.log(event.data); // The changed record
});
// Subscribe to a specific record
client.realtime.subscribe(["collections:appointments:abc123"]);Channel Patterns
| Pattern | Description |
|---|---|
collections:<name>:* | All changes to a collection |
collections:<name>:<id> | Changes to a specific record |
globals:<name> | Changes to a global |
Server-Side Broadcasting
Broadcast events from hooks or routes:
.hooks({
afterChange: async ({ data, operation, realtime }) => {
await realtime.broadcast(`collections:appointments:${data.id}`, {
type: operation,
data,
});
},
})Adapters
Configure the realtime adapter in your runtime config:
| Adapter | Package | Use case |
|---|---|---|
pgNotifyAdapter | Built-in | PostgreSQL LISTEN/NOTIFY |
redisStreamsAdapter | Built-in | Redis Streams (multi-instance) |
questpie.config.ts
import { pgNotifyAdapter, runtimeConfig } from "questpie";
export default runtimeConfig({
realtime: {
adapter: pgNotifyAdapter({
connectionString: process.env.DATABASE_URL,
}),
},
// ...
});For multi-instance deployments, use redisStreamsAdapter:
import { redisStreamsAdapter } from "questpie";
realtime: {
adapter: redisStreamsAdapter({
url: process.env.REDIS_URL,
}),
}Related Pages
- TanStack Query — Data fetching hooks
- Realtime (Production) — Infrastructure setup