Server-sent Events
- A one-way communication channel from server to client
- Suitable for realtime updates.
- Like one-way WebSockets
Vocabulary
- EventStream: What the server sends to the client.
- It's a text stream with a specific format
- EventSource: A browser API to consume an EventStream
Consuming SSE in the browser
The browser has a built-in API, EventSource
to consume server-sent events.
- Point to a URL that serves an event stream via
GET
request. - Listen to the
onmessage
event