# streamdata.io-events

> events API layer on top of streamdata

Latest version **1.2.2** (published 2017-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install streamdata.io-events
pnpm add streamdata.io-events
yarn add streamdata.io-events
bun add streamdata.io-events
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2017-11-03 |
| First published | 2017-10-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Jake Burden |
| Maintainers | jekrb |
| Keywords | steamdata, api, events |

## Links

- npm: https://www.npmjs.com/package/streamdata.io-events
- npm.io page: https://npm.io/package/streamdata.io-events

## Dependencies (3)

- [fast-json-patch](https://npm.io/package/fast-json-patch.md) ^2.0.5
- [streamdataio-js-sdk](https://npm.io/package/streamdataio-js-sdk.md) ^2.0.1
- [streamdataio-js-sdk-auth](https://npm.io/package/streamdataio-js-sdk-auth.md) ^2.0.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.2.2 (latest) — 2017-11-03
- 1.2.1 — 2017-11-03
- 1.2.0 — 2017-11-03
- 1.1.0 — 2017-11-02
- 1.0.1 — 2017-10-14
- 1.0.0 — 2017-10-11

## README

# streamdata.io-events

> events API layer on top of streamdata.io for Node.js and the browser

Events based API layer around [`streamdataio-js-sdk`](https://github.com/streamdataio/streamdataio-js-sdk) that handles `JSON Patch` by using [`fast-json-patch`](https://github.com/Starcounter-Jack/JSON-Patch).

## Usage


```js
var streamdata = require('streamdata.io-events')

var url = 'https://www.reddit.com/r/random.json?obey_over18=true'
var appToken = 'API key from https://streamdata.io/' // 🔑

var SSE = streamdata(url, appToken)

SSE
  .on('data', function (data) {
    console.log('data', data)
  })
  .on('error', function (err) {
    console.error(err)
  })

// close SSE after 5 seconds 
setTimeout(function () {
  SSE.close()
}, 5000)
```


## API

```js
var streamdata = require('streamdata.io-events')
var SSE = streamdata(url, appToken)
```

### `var SSE = streamdata(url, appToken, headers, privateKey)`

- url (string): http endpoint that you set streamdata to poll
- appToken (string): Your public auth key from streamdata.io
- headers (array) (optional): Array of optional headers such as `['header1: headervalue1', 'header2: headervalue2']`
- privateKey (string) (optional): Your private auth key from streamdata.io if you chose to generate one

`streamdata.io-events` is an event emitter!


### `SSE.on('data', callback(data))`

Occurs whenever a full JSON doc is available.  Is called when the SSE opens, and whenever a `JSON Patch` gets applied to the previous exisiting JSON doc. Uses `fast-json-patch` internally.

### `SSE.on('error', callback(err))`
Occurs whenever the SSE returns an error, sends an `Error` object in the callback.

### `SSE.on('end', callback())`
Occurs when the SSE closes.

### `SSE.on('patch', callback(patch))`
Occurs whenever a new patch becomes available. Use this if you want to have access to the patch directly. Normally you can just listen for the `data` event as it will pass you a patched JSON doc by using `fast-json-patch` internally.

### `SSE.on('opened', callback())`
Occurs whenever the stream is opened.

### `SSE.emit('open') || SSE.open()`
Opens the stream (is called automatically once when the SSE is instantiated).

### `SSE.emit('close') || SSE.close()`
Closes the stream.



## Install

With [npm](https://npmjs.org/) installed, run

```
$ npm install streamdata.io-events
```

## Acknowledgments

streamdata.io-events was inspired by https://streamdata.io/

## See Also

- [`streamdataio/streamdataio-js-sdk`](https://github.com/streamdataio/streamdataio-js-sdk)
- [`Starcounter-Jack/JSON-Patch`](https://github.com/Starcounter-Jack/JSON-Patch)

## License

MIT License
Copyright (c) 2017 Jake Burden

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---
_Source: https://npm.io/package/streamdata.io-events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
