api-websocket executes deterministic WebSocket request files, writes optional call history, and generates Markdown reports.
It follows the same CLI conventions as api-rest, api-gql, and api-grpc.
- Selected backend: native Rust transport via
tungsteniteinapi-testing-core::websocket::runner. - Rejected backend: external adapter (
websocat-style shell-out) for MVP. - Revisit when:
- streaming/session orchestration needs async multiplexing beyond scripted send/receive steps;
- platform/runtime behavior diverges in CI and a swap behind the transport boundary is justified.
- Runtime dependency policy: no extra external binary is required for WebSocket execution.
api-websocketuses the embedded Rust transport path only.
Canonical setup directory: setup/websocket.
WS_URL_<PROFILE>insetup/websocket/endpoints.env(optional local override:endpoints.local.env).WS_ENV_DEFAULTcan set a default endpoint profile.WS_URLcan force an explicit URL.
WS_TOKEN_<PROFILE>insetup/websocket/tokens.env(optional local override:tokens.local.env).WS_TOKEN_NAMEchooses a token profile.- If no profile is selected, fallback envs are
ACCESS_TOKENthenSERVICE_TOKEN.
URL precedence (call):
--url--env(profile lookup viaWS_URL_<PROFILE>, or literalws:///wss://)WS_URLWS_ENV_DEFAULTprofile- default
ws://127.0.0.1:9001/ws
Token precedence (call):
--tokenWS_TOKEN_NAME- profile lookup via
WS_TOKEN_<PROFILE> - env fallback
ACCESS_TOKENthenSERVICE_TOKEN
- Default history file:
<setup_dir>/.ws_history - Override:
WS_HISTORY_FILE - Controls:
WS_HISTORY_ENABLED,WS_HISTORY_MAX_MB,WS_HISTORY_ROTATE_COUNT,WS_HISTORY_LOG_URL_ENABLED
See docs/specs/websocket-request-schema-v1.md.
Quick example:
{
"url": "ws://127.0.0.1:9001/ws",
"steps": [
{"type": "send", "text": "ping"},
{"type": "receive", "expect": {"jq": ".ok == true"}},
{"type": "close"}
],
"expect": {"textContains": "ok"}
}call(default): execute request and print the last received message.history: print last entry or tail entries.report: generate Markdown report from--runor--response.report-from-cmd: reconstructreportargs from a savedcallsnippet.
Supported for call and history.
Success envelope:
{
"schema_version": "cli.api-websocket.call.v1",
"command": "api-websocket call",
"ok": true,
"result": {}
}Failure envelope:
{
"schema_version": "cli.api-websocket.call.v1",
"command": "api-websocket call",
"ok": false,
"error": {
"code": "stable-machine-code",
"message": "human-readable summary"
}
}Full CLI/JSON contract: docs/specs/websocket-cli-contract-v1.md
api-websocket call --env local setup/websocket/requests/health.ws.json
api-websocket call --format json --url ws://127.0.0.1:9001/ws setup/websocket/requests/health.ws.json
api-websocket history --tail 5
api-websocket report --case ws-health --request setup/websocket/requests/health.ws.json --run
api-websocket history --command-only | api-websocket report-from-cmd --stdin --dry-run