Skip to main content

Server-Sent Events (SSE)

Stream real-time updates for admin dashboards.

SSE flow

Endpoint

GET /wp-json/wc-appointments/v2/sse

  • Auth: Logged-in user with X-WP-Nonce.
  • Resume: since_id query or Last-Event-ID header.
  • Behavior: Streams up to 50 events, then ends.

Example

curl -H "X-WP-Nonce: YOUR_NONCE" \
"https://example.com/wp-json/wc-appointments/v2/sse?since_id=100"

Payload

{
"topic": "appointment.updated",
"resource": "appointment",
"resource_id": 123,
"payload": { "…": "minimal fields" },
"ts": 1730900000
}

Implementation

  • Route: includes/api/v2/class-wc-appointments-rest-v2-sse-controller.php
  • Events: includes/class-wc-appointments-sse.php
  • Client: EventSource with nonce header for admin pages.