>_ RESTERM
v1.18.2

examples Protocols

websocket_scripted.http

A WebSocket echo driven by @ws steps and checked by @assert and an @rts test block.

runs as-is

shell
resterm run _examples/websocket_scripted.http

Run this from the root of a clone of the Resterm repository.

Editor
### 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

_examples/websocket_scripted.http on GitHub

WebSocket and SSE docs
Search

↑↓ moveEnter openEsc close

Help

These keys work like the ones in the TUI.

/
Search the docs (also Ctrl K)
j k
Scroll down and up
g g G
Jump to the top or the bottom
[ ]
Previous and next page
g d
Docs index
g h
Home page
t
Switch between dark and light
?
Show this help
Esc
Close a dialog