Skip to main content
Directus provides real-time capabilities through WebSocket connections, enabling live updates, subscriptions, and collaborative editing features.

WebSocket Connection

Connect to Directus via WebSocket for bidirectional communication:

WebSocket URL

The WebSocket endpoint is available at:
For local development with HTTP:

Authentication

Authenticate your WebSocket connection:

Using Email & Password

Using Access Token

Using Refresh Token

Subscriptions

Subscribe to real-time updates for collections:

Subscribe to Collection

Subscription Events

WebSocket subscriptions emit different event types:
  • init - Initial data when subscription starts
  • create - New items matching the filter
  • update - Items updated to match the filter
  • delete - Items deleted or no longer match filter

Subscription Message Format

Live Queries

Execute live queries that update automatically:

Heartbeat

Maintain connection with heartbeat pings:
The SDK automatically handles heartbeats to keep the connection alive.

Connection Management

Connection Events

Disconnect

Reconnection

The SDK automatically attempts to reconnect on connection loss:

Collaborative Editing

Directus supports collaborative editing with operational transformation:

Presence

Track online users and their activity:

Real-Time Notifications

Implement live notification system:

Activity Feed

Create real-time activity streams:

Live Dashboard

Build real-time dashboards:

Performance Considerations

Filter Subscriptions

Always use filters to limit subscription data:

Limit Fields

Request only needed fields:

Unsubscribe When Done

WebSocket Configuration

Server Configuration

Error Handling

Best Practices

Only subscribe to data you need. Use filters to reduce bandwidth and processing.
Implement UI feedback for connection state and handle reconnection gracefully.
Clean up subscriptions when components unmount or data is no longer needed.
Enable heartbeats to detect stale connections and reconnect automatically.