Testing APIs

WebSockets and event streams

Connect to a WebSocket and send and receive messages live, or watch a server-sent event stream (SSE) as it arrives — with the same auth, headers and certificates as any request.

Most APIs answer once: you ask, they reply. Some keep the connection open and talk for as long as you listen:

  • A WebSocket is a two-way conversation — chat, live dashboards, trading, games, collaboration. Either side can send a message at any time.
  • Server-sent events (SSE) are one-way: the server keeps sending updates over an ordinary request — notifications, progress, prices, an AI answer arriving word by word.

APITestCenter shows both live, message by message, with the time each one came.

Connect to a WebSocket

  1. Type a WebSocket address in the URL bar. It starts with ws://, or wss:// for an encrypted one (like https://).
  2. Send becomes Connect — press it (or Ctrl+Enter).
  3. The Response panel shows the conversation as it happens:
  • ↙ messages that came in, ↗ messages you sent, and ⓘ notes about the connection (connected, closed and why);
  • each with the time since you connected; JSON is laid out on lines.
  1. To send a message, type it in the box under the log and press Send (or Ctrl+Enter). Text or JSON — whatever the server expects.
  2. Disconnect (where Connect was, or above the log) closes it. The log stays until you send or connect again.

Above the log: Filter shows only the messages that contain some text; Follow keeps the newest in view (untick it to read back while messages keep coming). Hover a message to copy it.

What goes with the connection

When it connects, the request's settings go with it, as with any request:

  • Headers from the Headers tab and from folders;
  • Auth: a Bearer token, Basic, an API key (in a header, or in the address), or OAuth 2.0 — the app gets the token. (OAuth 1.0, AWS Signature, JWT, Digest and NTLM aren't available for WebSockets yet.)
  • Cookies from the cookie jar — so if a login set a session cookie, the WebSocket is signed in too;
  • {{variables}} and built-in values in the address and headers;
  • Client certificates and the certificate check setting, for wss://.

Some servers want a subprotocol (Sec-WebSocket-Protocol). Add it as a header named Sec-WebSocket-Protocol on the Headers tab.

When it closes

The last line says why, with the WebSocket close code: 1000 (normal) — closed on purpose; 1001 (going away) — the server is restarting; 1006 (lost without a close message) — the network dropped, or the server crashed; 1008 (policy violation) or a 401/403 during connect — usually auth. A connection that fails to open says what went wrong (wrong address, refused, certificate).

Watch an event stream (SSE)

Nothing special to do: Send the request as usual. When the answer is an event stream (its content type is text/event-stream), the Body tab shows the events live instead of a body:

  • each event with its name (event:) and id (id:) when it has them, and its data (JSON laid out on lines);
  • Stop ends it from your side; The server ended the stream when it's done.

The status, headers and Request sent tabs work as for any answer.

Good to know

  • Collection runs leave WebSocket requests out (they say so). An event-stream request is run: the app reads the first 3 seconds of events, and its checks run on what came — the status, headers, or a body contains check on an event you expect.
  • Performance tests of WebSockets and streams aren't available yet.
  • The log keeps the latest 2,000 messages; a message over 100 KB is shortened in the log. Binary messages show their size and first bytes.
  • A connection nobody looks at for 10 minutes is closed; at most 5 are open at once.
  • From the command line and AI agents, an event stream is read for 3 seconds, like in collection runs.

Something unclear or missing? Write to support@apitestcenter.com — the guide improves with every question.