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

token

Yes

Stream token for the stream to subscribe to.

start_ts

Int

Stream start time in microseconds since the Unix epoch.

start_ts must be later than the creation time of the stream token.

The period between the stream restart and the start_ts can not exceed the history_days value for source Set’s collection. If a collection’s history_days is 0 or unset, the period can’t exceed 15 minutes.

Examples

[expand]

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!