cross.stream / docs
GitHub Discord

Store API

See When to Use Meta vs CAS for guidance on structuring frame data.

The supervisor exposes a HTTP API for interacting with the store. See Topics for naming rules and wildcards. By default, it listens on a Unix domain socket at ./store/sock.

Endpoints

GET /

Cat the stream

# Cat all frames
curl --unix-socket ./store/sock http://localhost/

# Long poll for new frames
curl --unix-socket ./store/sock -H "Accept: text/event-stream" \
    "http://localhost/?follow=true"

Query parameters are the read options: follow, new, after, from, limit, last, topic, and with-timestamp. A follow value may be true or a heartbeat interval in milliseconds.

Response: newline-delimited JSON frames or SSE stream, based on Accept header. Use "Accept: text/event-stream" for SSE.

POST /append/{topic}

Append frame to topic

curl --unix-socket ./store/sock \
    -H "xs-meta: $(echo -n '{\"key\":\"value\"}' | base64)" \
    -X POST --data "content" \
    "http://localhost/append/topic?ttl=forever"

Query Parameters:

Headers:

Response: Frame JSON

POST /append-batch

Append several frames in one request

printf '%s\n' \
    '{"topic":"clip.add","meta":{"n":1}}' \
    '{"topic":"clip.add","meta":{"n":2},"ttl":"last:100"}' |
  curl --unix-socket ./store/sock --data-binary @- \
    "http://localhost/append-batch"

Body: newline-delimited JSON, one frame per line. Each line takes:

The frames get consecutive IDs, with no other append interleaved, and are committed together: a reader sees all of them or none. A malformed line returns 400 and an invalid topic rejects the batch; either way nothing is stored.

A batch holds at most 1024 frames; a bigger one returns 400, with nothing stored. Split it into several requests.

Query Parameters:

Response: newline-delimited JSON, the stored frames in order

GET /{id}

Get frame by id

curl --unix-socket ./store/sock http://localhost/03BCPN2DNQ529QRQKBQCZ4JV4

Query Parameters:

Response: Frame JSON or 404 if not found

DELETE /{id}

Remove frame

curl --unix-socket ./store/sock -X DELETE \
    http://localhost/03BCPN2DNQ529QRQKBQCZ4JV4

Response: 204 on success

GET /last[/{topic}]

Get most recent frame(s), optionally filtered by topic.

curl --unix-socket ./store/sock http://localhost/last/topic
curl --unix-socket ./store/sock http://localhost/last
curl --unix-socket ./store/sock "http://localhost/last/topic?last=5"

Query parameters are the read options last (default: 1; returns NDJSON when > 1), follow, and with-timestamp.

Response: Most recent frame(s) as JSON (single) or NDJSON (multiple/follow), or 404 if not found

POST /cas

Store content in CAS

curl --unix-socket ./store/sock \
    -X POST --data "content" http://localhost/cas

Response: Content hash

GET /cas/{hash}

Get content from CAS

curl --unix-socket ./store/sock http://localhost/cas/sha256-hash

Response: Raw content or 404 if not found

POST /gc

Delete content no frame uses

curl --unix-socket ./store/sock -X POST http://localhost/gc

Removing or trimming a frame leaves its content in CAS, and an ephemeral frame's content is never kept by a stored frame. This deletes every content file no stored frame points at and that was written more than an hour ago. The hour leaves time for content uploaded with POST /cas to be appended, and for readers following the stream to fetch an ephemeral frame's content. The server also does this once each time it starts.

Response: JSON, what was found and deleted

{"in_use": 18, "recent": 87, "deleted": 28720, "bytes_freed": 10700000000}

POST /import

Import frame as-is

curl --unix-socket ./store/sock \
    -H "Content-Type: application/json" \
    -X POST --data '{"topic":"test","id":"03BCPN2DNQ529QRQKBQCZ4JV4"}' \
    http://localhost/import

Response: Imported frame JSON

POST /eval

Evaluate a Nushell script against the store. The request body is the script (UTF-8). The script runs with the store commands available (.cat, .last, .append, plus the core commands), so it can read from and write to the stream.

curl --unix-socket ./store/sock \
    -X POST --data '.cat | where topic == "notes" | length' \
    http://localhost/eval

Response: depends on the type the pipeline returns:

A script that fails to evaluate returns 500 with the error text.

GET /version

Get version info

curl --unix-socket ./store/sock http://localhost/version

Response: Version information JSON

Status Codes