star-wars-api
swapi.co (star wars api) wrapper for node
Install
$ npm install --save star-wars-api
Usage
var StarWarsAPI = ; swapi = ;
Get
All methods return a bluebird promise.
.get
requires two arguments, a resource
and an id
. id
can be a string
, number
, or array
.
swapi ; swapi // logs [{name: 'Death Star' ...}, {name: 'Millenium Falcon' ...}]
Errors and responses from swapi.co that are not of status code 200 will be rejected.
swapi // logs [Error] 404
Too few arguments to .get
also throws an error. All resources except a full url require an id
argument to passed to .get
with them.
// no id argument results in a rejected promiseswapi // doesn't log // logs [Error] id argument required // full resource url doesn't need idswapi // {name: 'Wookiee', language: 'Shyriiwook'...}
The full list of valid resources is:
people, films, starships, planets, vehicles, species
Convenience Methods
All valid resource argumets to .get
also have convenience methods:
swapiswapi// etc...
The full list of api resources can obtained from the api via .describe
swapi
License
MIT © Stephan Tabor