Realtime testing

Mock WebSocket, Socket.IO, and SSE Endpoints

Configure project-level realtime endpoints in the dashboard, synchronize them through the Mock API Studio CLI, and test WebSocket frames, Socket.IO events, and server-sent event streams on localhost.

Choose the realtime protocol

Use WebSocket for raw bidirectional frames, Socket.IO for named events and namespaces, or server-sent events when the server only needs to push an HTTP event stream to the client.

  • WebSocket endpoints use their configured path directly.
  • Socket.IO endpoints use the configured path as a namespace and /_mock/socket.io as the transport path.
  • SSE endpoints are regular HTTP GET streams and work with the browser EventSource API.

Configure typed server messages

Add one or more outbound messages and bind each payload to an exported TypeScript interface or type. The local runtime generates a fresh mock value for every emission. Choose Static JSON when the message must send one exact value instead.

TypeScript
export interface OrderUpdatedMessage {
  type: "order.updated";
  payload: {
    orderId: string;
    status: "paid" | "shipped";
    updatedAt: Date;
  };
}

Preview the wire message

Generate a sample in the endpoint editor before saving. The preview shows the serialized WebSocket frame, Socket.IO event and payload, or complete SSE event block that the client will receive.

Configuration
Name: Order updates
Protocol: WebSocket
Path: /orders/live
Payload source: TypeScript model
Payload type: OrderUpdatedMessage
Send on connect: enabled
Repeat interval: 1000 ms

Connect a WebSocket or Socket.IO client

Restart the local runtime after saving project changes. Standard WebSocket clients connect to the configured path. Socket.IO clients connect to the configured namespace and must use the Mock API Studio transport path.

JavaScript
const socket = new WebSocket("ws://localhost:4000/orders/live");
socket.onmessage = (event) => console.log(event.data);

const ioSocket = io("http://localhost:4000/chat", {
  path: "/_mock/socket.io"
});
ioSocket.on("message", console.log);

Consume an SSE stream

Create an EventSource for the configured HTTP path. The runtime sends the initial message immediately and repeats it when an interval is configured. Browser reconnection behavior remains available because the connection is a standard event stream.

JavaScript
const events = new EventSource("http://localhost:4000/feed");
events.addEventListener("update", (event) => {
  console.log(JSON.parse(event.data));
});

Understand the current scope

The first realtime version supports connection messages, scheduled messages, and optional echo behavior. It does not yet provide conditional message matching, multi-step scenarios, room management, binary fixtures, or production-style authorization handshakes.

Related questions

Is Socket.IO the same as a WebSocket endpoint?

No. Socket.IO uses its own event protocol and client library, even when WebSocket is the underlying transport. Choose the protocol that matches the application you are testing.

Keep exploring

Last updated September 17, 2026. Product behavior described here is verified against the current Mock API Studio runtime.