Problem
There is currently no way to inspect or control active WebSocket connections at runtime through the Admin API. Once a client connects to a WebSocket mock, the server has no management interface to:
- see which connections are currently open
- close a specific connection programmatically
- push a message from the server side to a connected client
This makes it impossible to fully test server-initiated WebSocket scenarios or clean up connections between test runs without restarting the entire mock server.
Proposed Solution
Add a WebSocket connection management group to the Admin API:
| Method |
Path |
Description |
GET |
/websocket/connections |
List all active connections with aggregate stats |
GET |
/websocket/connections/{id} |
Get details for a specific connection |
DELETE |
/websocket/connections/{id} |
Close a connection |
POST |
/websocket/connections/{id}/send |
Send a text or binary message to a connection |
GET |
/websocket/stats |
Get aggregate WebSocket statistics |
Use Case
Scenario 1 — Server-initiated push
A test needs to verify that a frontend correctly handles an incoming WebSocket event (e.g. a price update, a notification). Today this requires setting up a real backend. With this API the test can POST /websocket/connections/{id}/send to push the event directly from the mock.
Scenario 2 — Test cleanup
An integration test suite opens WebSocket connections during each test. Between runs the suite calls DELETE /websocket/connections/{id} (or iterates GET /websocket/connections) to forcefully close any lingering connections instead of restarting the server.
Scenario 3 — Monitoring & debugging
A developer watching a long-running test can query GET /websocket/stats or GET /websocket/connections to see how many clients are connected and how many messages have been exchanged, without needing to add custom logging.
Additional Context
The SSE protocol already has equivalent endpoints (GET /sse/connections, DELETE /sse/connections/{id}, GET /sse/stats) — the WebSocket API should mirror that design for consistency.
The underlying ConnectionManager in pkg/websocket/manager.go already exposes ListConnectionInfos, GetConnectionInfo, CloseConnection, and SendToConnection — the missing piece is the Admin API surface on top of it.
Problem
There is currently no way to inspect or control active WebSocket connections at runtime through the Admin API. Once a client connects to a WebSocket mock, the server has no management interface to:
This makes it impossible to fully test server-initiated WebSocket scenarios or clean up connections between test runs without restarting the entire mock server.
Proposed Solution
Add a WebSocket connection management group to the Admin API:
GET/websocket/connectionsGET/websocket/connections/{id}DELETE/websocket/connections/{id}POST/websocket/connections/{id}/sendGET/websocket/statsUse Case
Scenario 1 — Server-initiated push
A test needs to verify that a frontend correctly handles an incoming WebSocket event (e.g. a price update, a notification). Today this requires setting up a real backend. With this API the test can
POST /websocket/connections/{id}/sendto push the event directly from the mock.Scenario 2 — Test cleanup
An integration test suite opens WebSocket connections during each test. Between runs the suite calls
DELETE /websocket/connections/{id}(or iteratesGET /websocket/connections) to forcefully close any lingering connections instead of restarting the server.Scenario 3 — Monitoring & debugging
A developer watching a long-running test can query
GET /websocket/statsorGET /websocket/connectionsto see how many clients are connected and how many messages have been exchanged, without needing to add custom logging.Additional Context
The SSE protocol already has equivalent endpoints (
GET /sse/connections,DELETE /sse/connections/{id},GET /sse/stats) — the WebSocket API should mirror that design for consistency.The underlying
ConnectionManagerinpkg/websocket/manager.goalready exposesListConnectionInfos,GetConnectionInfo,CloseConnection, andSendToConnection— the missing piece is the Admin API surface on top of it.