octokit/rest.js

Name: rest.js

Owner: octokit

Description: GitHub REST API client for Node.js

Created: 2010-06-09 17:07:03.0

Updated: 2018-01-19 16:08:49.0

Pushed: 2018-01-19 07:35:07.0

Homepage: https://octokit.github.io/rest.js/

Size: 4285

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

rest.js

GitHub REST API client for Node.js

Build Status Coverage Status Greenkeeper npm

Usage

Install with npm install @octokit/rest.

t octokit = require('@octokit/rest')()

ompare: https://developer.github.com/v3/repos/#list-organization-repositories
kit.repos.getForOrg({
g: 'octokit',
pe: 'public'
hen(({data}) => {
 handle data

All available client options with default values

t octokit = require('@octokit/rest')({
meout: 0, // 0 means no request timeout
questMedia: 'application/vnd.github.v3+json',
aders: {
'user-agent': 'octokit/rest.js v1.2.3' // v1.2.3 will be current version


 change for custom GitHub Enterprise URL
st: 'api.github.com',
thPrefix: '',
otocol: 'https',
rt: 433,

 advanced request options
 see https://nodejs.org/api/http.html
oxy: undefined,
: undefined,
jectUnauthorized: undefined,
mily: undefined

@octokit/rest API docs: https://octokit.github.io/rest.js/
GitHub v3 REST API docs: https://developer.github.com/v3/

Authentication

Most GitHub API calls don't require authentication. Rules of thumb:

  1. If you can see the information by visiting the site without being logged in, you don't have to be authenticated to retrieve the same information through the API.
  2. If you want to change data, you have to be authenticated.
asic
kit.authenticate({
pe: 'basic',
ername: 'yourusername',
ssword: 'password'


auth
kit.authenticate({
pe: 'oauth',
ken: 'secrettoken123'


auth key/secret (to get a token)
kit.authenticate({
pe: 'oauth',
y: 'client_id',
cret: 'client_secret'


oken (https://github.com/settings/tokens)
kit.authenticate({
pe: 'token',
ken: 'secrettoken123'


itHub app
kit.authenticate({
pe: 'integration',
ken: 'secrettoken123'

Note: authenticate is synchronous because it only sets the credentials for the following requests.

Pagination

There are a few pagination-related methods:

Usage

c function paginate (method) {
t response = await method({per_page: 100})
t {data} = response
ile (octokit.hasNextPage(response)) {
response = await octokit.getNextPage(response)
data = data.concat(response.data)

turn data


nate(octokit.repos.getAll)
hen(data => {
// handle all results

DEBUG

Set DEBUG=octokit:rest* for additional debug logs.

Tests

Run all tests

m test

Or run a specific test

node_modules/.bin/mocha test/test/integration/get-repository-test.js

The examples are run as part of the tests. You can set an EXAMPLES_GITHUB_TOKEN environment variable (or set it in a .env file) to avoid running against GitHub's rate limit.

Contributing

We would love you to contribute to @octokit/rest, pull requests are very welcomed! Please see CONTRIBUTING.md for more information.

Credits

@octokit/rest was originally created as node-github in 2012 by Mike de Boer from Cloud9 IDE, Inc. It was adopted and renamed by GitHub in 2017

LICENSE

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.