Skip to content

Read streaming responses

wabe Disk uses three response forms. Choose the reader that matches the endpoint.

Endpoint Response body
GET /v1/disks/DISK/files/PATH Raw bytes, application/octet-stream.
GET /v1/disks/DISK/entries and KV scan NDJSON entries, one JSON object per line.
POST /v1/disks/DISK/exec NDJSON events with stdout, stderr, optional JS result and a terminal exit code.

A network chunk can contain part of a line or several lines. Buffer until newline when parsing NDJSON. A response body must be consumed or closed to release its disk lease.

This local Python process decodes exec records from stdin. Create the disk and obtain a project API key using the quickstart.

Print remote stdout and preserve the exit code
curl --fail-with-body --no-buffer \
"https://api.wabe.sh/v1/disks/demo/exec?kind=bash" \
-H "Authorization: Bearer YOUR_PROJECT_API_KEY" \
--data-binary 'printf "Hello\n"' |
python3 -c '
import base64, json, sys
exit_code = None
for line in sys.stdin.buffer:
event = json.loads(line)
if event["type"] in ("stdout", "stderr"):
stream = sys.stdout.buffer if event["type"] == "stdout" else sys.stderr.buffer
stream.write(base64.b64decode(event["data"]))
stream.flush()
elif event["type"] == "exit":
exit_code = event["code"]
sys.exit(125 if exit_code is None else exit_code)
'

An absent terminal exit record indicates an incomplete execution response. Stdout/stderr payloads use standard base64 so binary data survives JSON framing. A JS result record contains a JSON value directly. Directory and KV scan entries have no terminal exit event.

Use an encoded script query parameter or a stored JS path to make the HTTP request body stdin. Sending source in the body consumes that body as source. The exec reference lists all source forms.

Read a file response incrementally, or use fs.chunks(path) inside JavaScript. fs.readFile() materializes the entire file in the JS heap. KV get materializes one complete value; use files for larger payloads.

See the HTTP client recipe for an NDJSON reader that checks both HTTP errors and the command’s terminal exit code.