Skip to content

[FEATURE] Admin API WebSocket management #8

@pr0head

Description

@pr0head

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions