GET /simulations/{id}/stream

Stream a simulation's data as server-sent events.

Success

Respondes with a 200 OK and the following headers:

  • Content-Type: text/event-stream
  • Transfer-Encoding: chunked
  • Connection: keep-alive

Each event has a type specified by the event field. Currently, this will always be of the form: [stream name].create

The data field is a JSON-encoded string with the following properties:

  • stream is the stream name
  • offset is the number of milliseconds that had elapsed in the simulation when the event was emitted
  • value is the body of the event, and is currently always a JSON value

Failure

Responds with a 409 Conflict if this endpoint has previously been called for the simulation.

Examples

Data from a simulation with a single "users" stream.

event: users.create
data: {"stream":"users","offset":683878,"value":{"id": 1, "name": "Alice Jones"}}

event: users.create
data: {"stream":"users","offset":729698,"value":{"id": 2, "name": "Bob Hyland"}}

Stream simulation data to a JSON lines file in bash:

curl -N \
'https://api.rngo.dev/simulations/5fc3ffc9-8482-4478-861e-20707b92b142/stream' \
--header 'Authorization: Bearer rngo_ritrklsrqk_t09agnzb8wfnt2p' \
| grep -o '^data: .*' \
| sed 's/^data: //' \
| jq -r '.value' \
> users.jsonl