2.0.2 • Published 6 years ago

swapi-stream v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

swapi-stream

Download swapi data using a read stream.

Requirement

  • Node >= 8.0.0 (swapi-stream 1.x works with node 6.0.0)
  • To be fan of Star Wars

Installation

npm install --save swapi-stream

Usage

To get films list:

const swapiStream = require('swapi-stream');
const result = swapiStream.get(swapiStream.FILMS);
result.on('data', data => console.log(data.title));
result.on('error', (error) => console.log('ERROR', error.toString()));
result.on('end', () => console.log('END'));

To get planets list:

const swapiStream = require('swapi-stream');
const result = swapiStream.get(swapiStream.PLANETS);
result.on('data', data => console.log(data.title));
result.on('error', (error) => console.log('ERROR', error.toString()));
result.on('end', () => console.log('END'));

API

const myStream = swapiStream.get(<resourceName>);

resourceName is mandatory. It's the resource name as defined swapi data Rest API. Rather than typing the name, you can use swapiStream constants (like shown in above examples):

  • FILMS
  • PEOPLE
  • PLANETS
  • VEHICLES
  • STARSHIPS
  • SPECIES

swapiStream.get returns a stream emitting the regular events data, end and error. As it's a stream, it returns all entities of the resource. If this does not suit your need, you may prefer a module that returns entities page by page like swapi-node.

2.0.2

6 years ago

2.0.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago