SSE Server Sent Events
Server Sent Events SSE are a well established web standard.
They allow a web server to push messages to the client.
I have created a minimal example https://github.com/janhalfar/sse-playground/tree/main/minimal to illustrate the technology.
Minimal Example in action
if you clone https://github.com/janhalfar/sse-playground locally and run
go run minimal/main.go
This server will:
- serve its minimal frontend on http://localhost:8080
- serve a time event 100 times on http://localhost/sse/time
Let´s take a look at the server response with:
curl -v localhost:8080/sse/time
% curl -v localhost:8080/sse/time
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /sse/time HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.79.1
> Accept: */*
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: text/event-stream
< Date: Fri, 16 Sep 2022 14:49:17 GMT
< Transfer-Encoding: chunked
serving the frontend
The first thing the server is to serve a frontend, which is described below:
serving time events