A really simple GitHub API wrapper for Node.js
npm install node-github-wrapper
var githubAPI = require('node-github-wrapper')(options);
Option | Description | Default value |
---|---|---|
appName | Name of the application. Will be used in the request headers | |
apiRoot | Base URL of the GitHub API | https://api.github.com |
headers | Headers to be sent with all requests | {'Accept': 'application-json', 'User-Agent': appName} |
This library can handle the OAuth authentication with the GitHub API. The following is a typical workflow:
- Generate a auth URL by calling
getAuthURL()
. By accessing that URL, users will be asked for permission to give your app access to their account; - When permission is granted, a callback URL will be called along with an authorization code. This code can be passed to
authorize()
which will exchange that code for an access token.
Alternatively, if you're already in the possession of a valid access token (i.e. you stored it in a database for subsequent requests), you can call setAccessToken()
directly to authenticate requests.
Generates a URL that redirects users to request GitHub access
Exchanges the OAuth code for an access token and runs the callback function
Sets the access token to be used by all requests that require authorization.
Sends a GET
request to the API, with request data and a callback function.
Sends a POST
request to the API, with request data and a callback function.
Sends a PUT
request to the API, with request data and a callback function.
Sends a DELETE
request to the API, with request data and a callback function.
Each requests receives as an argument an object with a set of options.
API endpoint, without the API root prefix.
{url: '/user'}
Generates https://api.github.com/user.
A list of key/value parameters to be added to the endpoint URL.
{
url: '/user',
urlParameters: {
foo: 'bar',
baz: 'qux'
}
Generates https://api.github.com/user?foo=bar&baz=qux.
The body to include in the request, in JSON format.
body: {
foo: 'bar',
baz: 'qux'
}
Overrides the default headers to be sent with the request.
headers: {
'Accept': 'application/json',
'User-Agent': 'My app name'
}
Whether to authenticate the request. Defaults to false
.
auth: true