Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/segment-boneyard/sse

A Server-Sent Events component
https://github.com/segment-boneyard/sse

Last synced: about 5 hours ago
JSON representation

A Server-Sent Events component

Awesome Lists containing this project

README

        

# sse

A nice [Server-Sent Events](http://www.html5rocks.com/en/tutorials/eventsource/basics/) api

## Example

With a SSE endpoint that responds like this:

```bash
$ curl http://localhost/updates
data: foo

data: bar

data: quit

```

And a script that subscribes to its updates:

```js
var sse = require('sse');

var unbind = sse('/updates', function(data){
if (data == 'quit') unbind();
console.log(data);
});
```

The console output will be:

foo
bar
quit

## Installation

Install with [component(1)](http://component.io):

$ component install segmentio/sse

## API

### sse(url, fn)

Subscribe `fn` to events on `url`. Returns an `unbind` function.

## License

MIT