17 releases
Uses new Rust 2024
| 0.6.5 | Mar 8, 2026 |
|---|---|
| 0.6.3 | Mar 2, 2026 |
| 0.5.9 | Feb 28, 2026 |
| 0.4.9 | Feb 23, 2026 |
#27 in WebSocket
645KB
17K
SLoC
api-websocket
Overview
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.
Transport decision
- 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
- Runtime dependency policy: no extra external binary is required for WebSocket execution.
api-websocketuses the embedded Rust transport path only.
Setup and naming conventions
Canonical setup directory: setup/websocket.
Endpoint variables
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.
Token variables
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/token precedence
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
History
- 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
Request schema (v1)
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"}
}
Commands
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.
JSON contract (--format json)
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
Quickstart
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
Docs
Dependencies
~13–30MB
~400K SLoC