WebSocket Mock

WebSocket Mock

The WS / Socket Mock feature lets you spin up a fully functional WebSocket or Socket.io server in one click. Use it to test real-time features in your frontend without any running backend — define events, set schedules, and watch live connections from the dashboard.

Creating a project

  1. Go to WS / Socket Mock in the MockLab dashboard.
  2. Click New Project and give it a name (e.g. my-app-ws).
  3. Choose protocol: WebSocket or Socket.io.
  4. Your server is live instantly — copy the connection URL and use it in your frontend.
Plan limits
Free1 project
Pro20 projects

Connection URLs

Each project gets a unique connection URL based on your project key:

WebSocket
wss://ws.mocklab.dev/v1/your-project-key
Socket.io
https://ws.mocklab.dev/v1/your-project-key

Connecting from your frontend

Native WebSocket (browser)
const ws = new WebSocket('wss://ws.mocklab.dev/v1/your-project-key');

ws.onopen = () => {
  console.log('Connected to MockLab WS');
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Received event:', data);
};

ws.onclose = () => {
  console.log('Disconnected');
};
Socket.io client
import { io } from 'socket.io-client';

const socket = io('https://ws.mocklab.dev/v1/your-project-key', {
  transports: ['websocket'],
});

socket.on('connect', () => {
  console.log('Connected, socket ID:', socket.id);
});

socket.on('order:updated', (data) => {
  console.log('Order update received:', data);
});

socket.on('disconnect', (reason) => {
  console.log('Disconnected:', reason);
});

Dashboard tabs

Events
Docs →
Define named events with payloads. Trigger manually or from a schedule. Broadcast to all clients or target a specific client ID.
Schedules
Docs →
Configure events to fire automatically on a repeating interval (1s, 30s, 5m, etc.). Start, pause, and stop from the dashboard.
Connections
See all currently connected clients in real time — client ID, IP address, protocol, connection time, and last event received.
Logs
View the last 1,000 events — both sent and received. Includes direction, event name, payload, and client ID. Auto-refreshes every 5s.
Settings
Docs →
Configure scenario mode (Success/Error/Slow), enable API key auth for connections, rotate keys, and delete the project.

API key authentication

Enable connection auth in project Settings to require an API key for connections. This lets you test authentication error paths in your frontend.

Connect with API key (Socket.io)
const socket = io('https://ws.mocklab.dev/v1/your-project-key', {
  auth: {
    token: 'your-project-api-key'
  }
});

// If the token is missing or wrong:
socket.on('connect_error', (err) => {
  console.error('Auth failed:', err.message);
  // → "Authentication required" or "Invalid API key"
});