GET
Subscribe to a stream.
curl -X GET \
'https://db.fauna.com/stream/1' \
-H 'Authorization: Bearer $FAUNA_SECRET' \
-H 'Content-Type: application/json' \
-d '{"token": "<STREAM_TOKEN>", "start_ts": 1710968002310000}'
Request
Content-Type: application/json
Schema
Field name | Type | Required | Description |
---|---|---|---|
|
Yes |
Stream token for the stream to subscribe to. |
|
|
Stream start time in microseconds since the Unix epoch.
The period between the stream restart and the |
Examples
You typically create and subscribe to streams using a Fauna client driver. The drivers include methods to create and connect to event streams. See Stream basics.
If using the HTTP API, you create a stream token using an FQL query and the
query/1
endpoint. In the query, append
toStream()
or
changesOn()
to a set from a
supported
source:
curl -X POST \
'https://db.fauna.com/query/1' \
-H 'Authorization: Bearer $FAUNA_SECRET' \
-H 'Content-Type: application/json' \
-d '{"query": "Manager.all().toStream()"}'
Response:
{
"data":"g9WD1YPG...", // Stream token
"static_type":"Stream<Manager>",
"summary":"",
"txn_ts":1718340750415639,
"schema_version":1718034700060000
}
Then use the token to subscribe to the stream:
curl -X GET \
'https://db.fauna.com/stream/1' \
-H 'Authorization: Bearer $FAUNA_SECRET' \
-H 'Content-Type: application/json' \
-d '{"token": "<STREAM_TOKEN>", "start_ts": 1710968002310000}'
Response
Content-Type: application/json
A successful request starts a
stream. When the stream starts,
Fauna responds with a status
event.
{
"type": "status",
"txn_ts": 1710968002310000,
"stats": {
"read_ops": 8,
"storage_bytes_read": 208,
"compute_ops": 1,
"processing_time_ms": 0,
"rate_limits_hit": []
}
}
The connection remains open so Fauna can notify the client of new events. See Event Streaming reference.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!