JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 350
  • Score
    100M100P100Q89402F
  • License MIT

Basic https interface to GitHub

Package Exports

  • github-basic

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (github-basic) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

github-basic

Basic https interface to GitHub

Build Status Dependency Status NPM version

Installation

npm install github-basic

API

github(method, path, query, options, callback)

Make a request to one of the github APIs. Handles redirects transparently and makes errors into proper error objects

Usage

var github = require('github-basic')

//get all 'ForbesLindesay's gists in the last year

var since = new Date()
since.setUTCFullYear(since.getUTCFullYear() - 1)

// using callbacks

github('GET', '/users/:user/gists', {user: 'ForbesLindesay', since: since}, function (err, res) {
  if (err) throw err;
  res.body.pipe(process.stdout)
})

// or

github('GET', '/users/ForbesLindesay/gists', {since: since}, function (err, res) {
  if (err) throw err;
  res.body.pipe(process.stdout)
})

// using promises

github('GET', '/users/:user/gists', {user: 'ForbesLindesay', since: since})
  .done(function (res) {
   res.body.pipe(process.stdout)
  })

//or

github('GET', '/users/ForbesLindesay/gists', {since: since})
  .done(function (res) {
   res.body.pipe(process.stdout)
  })

Parameters

  • @param {String} method: Can be head, get, delete, post, patch or put
  • @param {String} path: Path from the docs, e.g. /gists/public or /users/:user/gists
  • @param {Object} query: Query options, e.g. {since: new Date(2000, 0, 1)} or {user: 'ForbesLindesay'}
  • @param {Object} options: All the other options
  • @param {Function} callback: If ommitted, a promise is returned

Options

  • auth: (default: null) {type:'oauth',token:'<my oauth token>'} or {type:'basic',username:'my user',password:'my password'}
  • timeout: (default: 2 minutes) timeout in ms or string parsed by ms like '30 minutes'
  • protocol: (default: https) can be http or https
  • host: (default: api.github.com) can be api.github.com, github.com or gist.github.com
  • headers: (default: {}) override default headers in the request

Result

A standard response object with a readable stream as the .body property. (N.B. don't stream res, stream res.body)

github.buffer(method, path, query, options, callback)

Same as github(method, path, query, options, callback) except res.body is a string containing the buffered response

github.json(method, path, query, options, callback)

Same as github(method, path, query, options, callback) except res.body is a JSON object containing the parsed response

License

MIT