An open API service indexing awesome lists of open source software.

https://github.com/clarketm/express-sse-example

Real-time Express streaming API leveraging Server Sent Events (SSE)
https://github.com/clarketm/express-sse-example

express server-sent-events sse streaming-api

Last synced: 6 months ago
JSON representation

Real-time Express streaming API leveraging Server Sent Events (SSE)

Awesome Lists containing this project

README

          

# express-sse-example
Real-time Express streaming API leveraging Server Sent Events (SSE)

### Example

#### Start
```bash
$ npm start
```

#### Subscribe (server-side)
```bash
# GET /eventstream
$ curl -XGET "http://localhost:3000/eventstream"
```

#### Subscribe (client-side)
```js
const es = new EventSource("http://localhost:3000/eventstream");
es.addEventListener("message", event => console.log(JSON.parse(event.data)));
```

#### Publish a "message" event
```bash
# POST /message
$ curl -XPOST "http://localhost:3000/message" -d "some message"
```

#### All subscribers will receive the event payload
```json
{
"message": "some message",
"timestamp": "2018-09-12T07:25:45.403Z"
}
```