Realtime
Sse Endpoint
SSE endpoint for real-time subscriptions.
GET
/
api
/
v1
/
realtime
/
subscribe
Sse Endpoint
curl --request GET \
--url https://api.example.com/api/v1/realtime/subscribeimport requests
url = "https://api.example.com/api/v1/realtime/subscribe"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.example.com/api/v1/realtime/subscribe', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/realtime/subscribe",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/realtime/subscribe"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/api/v1/realtime/subscribe")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/realtime/subscribe")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_bodySSE Endpoint
Connect to this endpoint for real-time updates via Server-Sent Events (SSE). Connection URL:http://localhost:8000/api/v1/realtime/subscribe?token={jwt_token}&collection=posts
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| token | string | Yes | JWT access token |
| collection | string | No | Collection to subscribe to (can be specified multiple times) |
Server Events
Heartbeat Event
Sent every 30 seconds to keep the connection alive.event: heartbeat
data: {"timestamp": "2026-01-17T12:34:56.789Z"}
Message Event
Sent when a subscribed collection has data changes.event: message
data: {"type": "posts.create", "timestamp": "2026-01-17T12:34:56.789Z", "data": {...}}
Event Format
All data events follow this structure:{
"type": "posts.create",
"timestamp": "2026-01-17T12:34:56.789Z",
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "New Post",
"created_at": "2026-01-17T12:34:56.789Z"
}
}
Connection Behavior
- Automatic reconnection handled by the browser
- Token expiration will close the connection
- Heartbeat sent every 30 seconds
Example
const token = "your_jwt_token";
const eventSource = new EventSource(
`http://localhost:8000/api/v1/realtime/subscribe?token=${token}&collection=posts`
);
eventSource.addEventListener("message", (event) => {
const message = JSON.parse(event.data);
if (message.event === "heartbeat") {
console.log("Heartbeat received");
return;
}
console.log("Event received:", message);
// Update your UI
});
eventSource.onerror = (error) => {
console.error("SSE error:", error);
};
// Close the connection when done
// eventSource.close();
Multiple Collections
Subscribe to multiple collections by specifying thecollection parameter multiple times:
http://localhost:8000/api/v1/realtime/subscribe?token={token}&collection=posts&collection=comments
Response
200 - application/json
Successful Response
⌘I
Sse Endpoint
curl --request GET \
--url https://api.example.com/api/v1/realtime/subscribeimport requests
url = "https://api.example.com/api/v1/realtime/subscribe"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.example.com/api/v1/realtime/subscribe', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/realtime/subscribe",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/realtime/subscribe"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/api/v1/realtime/subscribe")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/realtime/subscribe")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body