WebSockets, GraphQL and WebRTC
Not every API is one request and one answer. Four more methods live in the same files as the rest, with the same variables, directives and assertions: WS for a WebSocket, GRAPHQL for a GraphQL endpoint, and STUN and TURN for the two kinds of server a WebRTC call leans on.
Start with a socket. This one connects to a public echo server, says hello, and checks that hello comes back. It runs as it stands.
### Say hello
WS wss://ws.postman-echo.com/raw
> send "hello"
> receive 5s
> assert message == "hello"
> close
The request line opens the connection, and either spelling of the URL works: http becomes ws, https becomes wss. Headers go into the handshake, which is where a token belongs, and a body, if the request has one, is sent as the first message. Then the script runs top to bottom against the open connection.
send value | writes a message; an object or an array goes out as JSON |
receive, receive 5s | waits for the next message, ten seconds by default. message is its text and data its JSON, both null when nothing came |
wait 500ms | pauses |
close | hangs up; the connection also closes when the script ends |
stamp run chat.stamp
→ WS wss://ws.postman-echo.com/raw chat.stamp › sayHello
101 Switching Protocols 859 ms 215 bytes
✓ message == "hello"
✓ 1 request, 1 assertion
The status is the handshake, 101, and the size is the whole conversation rather than one body. A receive that runs out of time is not a failure by itself: it leaves message and data empty and notes the wait in the console, so the assertion after it is what fails, with the message you gave it.
Most sockets carry JSON rather than text. Send an object and it goes out as JSON; receive parses what comes back into data and keeps the raw text in message.
### Join the room
WS wss://ws.postman-echo.com/raw
> send { type: "join", room: "support", user: "ada" }
> receive 5s
> assert data.type == "join"
> assert data.room == "support"
> wait 500ms
> send "ping"
> receive 5s
> assert message == "ping"
> close
GraphQL. A GRAPHQL request sends its body as a GraphQL operation. What goes over the wire is a JSON POST, which is what the output names, so headers, @auth and scripts behave as they do everywhere else.
### Continents
GRAPHQL https://countries.trevorblades.com/graphql
{
continents { code name }
}
> assert body.errors == null
> assert length(body.data.continents) == 7
Variables follow the query after an empty line, as a JSON object, and they interpolate like any other body, so a value from the workspace can travel into a GraphQL variable.
### Country
GRAPHQL https://countries.trevorblades.com/graphql
query Country($code: ID!) {
country(code: $code) { name capital emoji }
}
{ "code": "CH" }
> assert body.errors == null
> assert body.data.country.capital == "Bern"
A GraphQL server answers 200 even when the query was wrong, so assert status == 200 proves little on its own. assert body.errors == null is the line that catches a renamed field.
The last two methods answer one narrow question: why a WebRTC call will not connect. Stop here if that is not the question you came with.
A call needs working ICE servers. A STUN server tells a peer the address the world sees it at; a TURN server relays the media when no direct path exists. Both take the URLs RTCPeerConnection takes: stun:host:port, turn:host:port?transport=tcp, and turns:host:port for TLS. The response is a report of what the check found rather than something the server sent back.
### Public address
STUN stun:stun.l.google.com:19302
> assert status == 200
> assert body.mapped.port > 0
> assert body.rtt < 500
> print "reachable as " + body.mapped.address
mapped | address, port and family of the public address the server saw |
relayed, lifetime | the relay a TURN server allocated, and the seconds it would have lasted |
rtt, local | the round trip in milliseconds, and the local address the check went out from |
behindNAT | whether the public address differs from the local one |
realm, authenticated, software, error | what the server said about itself and about this request |
A TURN server wants credentials, which come from @auth basic. The check allocates a relay, reports it, then releases it. Asking without credentials is still worth a request of its own: the answer is 401 and it names the realm, which proves the server is up and listening. The snippet below needs a server of your own, with turnUser and turnPassword in environment.local.stamp, so it will not run as it stands.
### Relay
@auth basic {{turnUser}} {{secret(turnPassword)}}
TURN turns:turn.example.com:5349
> assert status == 200
> assert body.relayed != null
> assert body.lifetime > 0
The status is 200, or the server's own STUN error code: 401 with credentials missing or wrong, and 437, 438 or 486 when the allocation itself went wrong. Signaling, the part that carries the offer and the answer between peers, is the application's own business, and a WS request with send and receive covers that exchange.
In the app
- Click the method at the left of the address field and pick WS. It sits below the HTTP methods and GRAPHQL, with STUN, TURN and MCP under it.
- Type the address, then open the Tests tab and write the script there. The line under the editor lists what it takes:
send,receive,wait,close,assert,set,print. - Press ⌘↩. The status line reads 101, with the time the conversation took and the size of all of it.
- The first tab of the response is now called Messages and carries how many there were. The exchange is laid out like a chat: what you sent on the right, what came back on the left, each one marked Sent or Received with how far into the conversation it arrived. JSON is shown formatted.
- A GRAPHQL request keeps all five tabs, and the query and its variables go in Body exactly as they sit in the file. STUN and TURN have only Auth and Tests, and their report is JSON, so it reads in Pretty or Tree like any other body.
The file gives the order; the window gives the timing. A reply that took two seconds to arrive is visible as that, and a receive that waited and got nothing leaves its note in the Console tab, next to the assertion that then failed.

Next: Requests for everything these four share with a plain GET, Scripts and assertions for what else a script can check, and MCP servers for the one other method with a conversation of its own.