Reference
The Streaming API allows you to subscribe to the events related to the corresponding entities via the WebSocket interface. As we prioritize even delivery over redundancy, in some rare cases, the same event may arrive twice. Make sure to track the unique source of the event, like deploy hash and event id, where needed.
The update events are emitted only when the direct entity properties are changed. Changes in the optional fields will not trigger a WebSocket message.
Streaming API connection may close when a new version of the API is deployed; thus, make sure to include the reconnection logic in your code.
Format
The messages are sent as JSON objects with the following properties:
action
string
Action name
data
Entity
Affected entity
timestamp
datetime
Timestamp of the network object, deploy or block, that triggered the action
extra
mixed
Extra data provided with the message. This property is optional.
Persistent sessions (beta)
Applications may experience failures on their end, resulting in closing the WebSocket connections. To ensure no messages are lost during the downtime, it's possible to declare the WebSocket connection as "persistent" by adding a Persistent-Session
header. Reconnecting with the same Persistent-Session
header value would connect the application to the same queue containing the messages received during the downtime.
Persistent Streaming API sessions not available for the "Free" tier
Streams
Below is a full list of the available CSPR.cloud Streaming API streams:
Prerequisites
To follow Streaming API examples you'll need to install the wscat
NPM utility:
Last updated