Skip to main content

WebSocket Schema ([websocket])

When protocol = "websocket" is defined, Rumour initiates an HTTP Upgrade request. The [websocket] block dictates the connection settings and the precise script of actions to execute over the real-time stream.


Actionable Quickstart​

Want to test this schema right now? You can run it against the official rumour-mock-server repository.

1. Start the Mock Server​

In a new terminal window, boot up the multi-protocol mock server (provides a WebSocket Echo server on port 4001):

cd rumour-mock-server/mock-server
npm install
npm start

2. Scaffold a Workspace​

In your main terminal, initialize a fresh testing workspace:

mkdir try_ws
cd try_ws
rumour init
rumour new ws_tests

3. Create the Request File​

Paste this complete request into ws_tests/request.toml. This scripts a real-time sequence against the echo server:

name = "quickstart_ws"
protocol = "websocket"

[request]
url = "ws://localhost:4001"

[websocket]
timeout_ms = 5000
expect_message = "PING"

# Push a payload down the socket
[[websocket.messages]]
text = "PING"

[assert]
status = 101 # Assert successful WS Upgrade Handshake

4. Run the Test​

Execute the test and watch Rumour step through the real-time script automatically:

rumour run ws_tests/ -v

Root Parameters ([websocket])​

FieldTypeDefaultDescription
timeout_msInteger5000The maximum time allowed in milliseconds for connection establishment and message exchange.
actionString"send"Action mode for single-message execution. Options: "send", "listen", "connect", "close".
expect_messageString—Substring pattern expected in the received WebSocket frame. If not received within timeout_ms, Rumour sets the status code to 417 Expectation Failed with x-ws-expect-failed header.
message_typeString"text"The default frame type to use when sending single payloads from [body]. Options: "text", "binary".
[websocket]
timeout_ms = 10000
action = "send"
expect_message = "pong"
message_type = "text"

The Sequence Array ([[websocket.messages]])​

When sending one or more messages across the socket, use the [[websocket.messages]] array of tables. Rumour queues and transmits these messages in strict chronological order upon establishing the connection:

FieldTypeRequiredDescription
textStringNoText string to send as a WebSocket text frame.
binaryStringNoBase64-encoded string decoded and sent as a binary WebSocket frame.
delay_msIntegerNoArtificial delay in milliseconds to wait before transmitting this message frame.

Message Frame Examples​

1. Text Message Frame​

Pushes a text or JSON payload down the socket:

[[websocket.messages]]
text = '{"type": "subscribe", "channel": "alerts"}'

2. Delayed Message Frame​

Pauses for the specified milliseconds before sending the next frame:

[[websocket.messages]]
text = "PING"
delay_ms = 1000

3. Binary Message Frame​

Sends a base64-encoded binary payload:

[[websocket.messages]]
binary = "SGVsbG8gV29ybGQ=" # Base64 for "Hello World"

Single-Message Shorthand ([body])​

For simple interactions without the [[websocket.messages]] array, define the payload in [body] and configure action and expect_message in [websocket]:

[request]
url = "ws://localhost:4001"

[body]
raw = '{"action": "ping"}'

[websocket]
action = "send"
expect_message = '"action":"pong"'
timeout_ms = 5000