Git Product home page Git Product logo

gh-api's Introduction

gh-api

stable

A thin utility for GitHub API requests in Node and the browser. After browserify and uglify, it bundles to 9kb.

For a streaming alternative that supports pagination, see gh-api-stream.

Install

npm install gh-api --save

Example

For example, getting a package.json from a GitHub repository:

var github = require('gh-api')

var api = '/repos/mattdesl/gh-api/contents/package.json'
github(api, function (err, data, res) {
  if (err) throw err
  
  console.log(res.statusCode)
  //> 200
  
  var buf = new Buffer(data.content, data.encoding)
  var pkg = JSON.parse(buf.toString())
  
  console.log(pkg.description)
  //> 'simple GitHub API requests in Node / browser'
})

For simple pagination, you can use parse-link-header on res.headers.link.

Usage

NPM

req = ghApi(path, [opt], [cb])

Sends a request to the GitHub API at the specified path, such as '/repos/:owner/:repo/readme'.

Options can be:

  • token an optional GitHub API token for authentication
  • query (String|Object) optional query parameters for the URL
  • method (String) the method to use, default 'GET'
  • timeout (Number) milliseconds before timeout, default 0 (no timeout)
  • headers optional headers object to override the defaults

Other options, such as json, are passed to xhr-request.

The callback is called with the arguments (error, data, response)

  • error on success will be null/undefined
  • data the result of the request, either a JSON object, string, or ArrayBuffer
  • response the request response, see below

The response is normalized by xhr-request in Node and the browser.

req = ghApi.url(url, [opt], [cb])

Same as above, but expects a full url to the GitHub endpoint.

req.abort()

Cancels a pending request and sends an error to the callback.

See Also

License

MIT, see LICENSE.md for details.

gh-api's People

Contributors

mattdesl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.