gh-api-stream
Streams paginated JSON from a GitHub API.
var api = // prints all my follower's usernames
For a non-streamed and browser-friendly alternative, see gh-api.
Install
npm install gh-api-stream
Examples
Below is an example of paging through all 'open'
issues in a repo. It parses the JSON by row rather than buffering it all at once. Uses ghauth for easy authentication.
var api = var ghauth =
See test/example.js for another example.
Usage
stream = ghApiStream(api, [opt])
Returns an object stream that emits 'data'
results from the request.
api
is a String for the API like '/repositories'
or '/orgs/:owner/repos'
.
The options:
token
(String)- optional authentication token
pages
(Number)- if specified, will limit the request to no more than N pages. Otherwise streams until we have no remaining pages
rows
(Boolean|String|Array)- if
true
, parses the JSON in rows, emitting a'data'
event for each row. Iffalse
or undefined, it will buffer and emit the entire JSON - Strings and Arrays are passed to JSONStream
parse
path, e.g.'*.user.login'
- if
Other options are passed to got, like query
, method
and body
. Requests use 'https://api.github.com/'
as a URL base.
stream = ghApiStream.url(url, [opt])
You can use this to pass a full URL to your API endpoint. The options are the same as above.
var api = var stream = api
See Also
- gh-api - a non-streamed alternative suitable for the browser
- gh-got - a related library built on got
License
MIT, see LICENSE.md for details.