examples Protocols
websocket_scripted.http
A WebSocket echo driven by @ws steps and checked by @assert and an @rts test block.
runs as-is
resterm run _examples/websocket_scripted.httpRun this from the root of a clone of the Resterm repository.
Editor
WebSocket and SSE docs### Scripted WebSocket Echo
# @name WebSocketScriptedEcho
# @websocket timeout=10s idle=1s
# @assert stream.enabled() => "stream should be enabled"
# @rts test "echo reply received"
> {%
let events = stream.events()
# The server may send other messages first, so match the echo by its text.
let sent = null
for let _, ev range events {
if ev.direction == "send" and ev.type == "text" {
sent = ev.text
break
}
}
if sent == null {
t.fatal("no text message was sent")
}
let echoed = false
for let _, ev range events {
if ev.direction == "receive" and ev.text == sent {
echoed = true
break
}
}
if not echoed {
t.error("no reply matches the sent text:", sent)
}
%}
# @ws send Hello from Resterm
# @ws wait 1s
# @ws close 1000 scripted close
wss://echo.websocket.org