@octokit/rest
GitHub REST API client for Node.js
Last updated 7 years ago by octokitbot .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @octokit/rest 
SYNC missed versions from official npm registry.

rest.js @latest @next

GitHub REST API client for Node.js

Build Status Coverage Status Greenkeeper

Usage

Node

Install with npm install @octokit/rest.

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

// Compare: https://developer.github.com/v3/repos/#list-organization-repositories
octokit.repos.getForOrg({
  org: 'octokit',
  type: 'public'
}).then(({data}) => {
  // handle data
})

Browser

  1. Download octokit-rest.min.js from the latest release: https://github.com/octokit/rest.js/releases

  2. Load it as script into your web application:

    <script scr="octokit-rest.min.js"></script>
    
  3. Initialize octokit

    const octokit = new Octokit()
    
    // Compare: https://developer.github.com/v3/repos/#list-organization-repositories
    octokit.repos.getForOrg({
      org: 'octokit',
      type: 'public'
    }).then(({data}) => {
      // handle data
    })
    

Client options

All available client options with default values

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

  // change for custom GitHub Enterprise URL
  host: 'api.github.com',
  pathPrefix: '',
  protocol: 'https',
  port: 443,

  // Node only: advanced request options can be passed as http(s) agent
  agent: undefined
})

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

API Previews

To take advantage of GitHub’s API Previews, pass a custom accept header, which you can do with any endpoint method documented in the API docs, e.g.

const {data: {topics}} = octokit.repos.get({
  owner: 'octokit',
  repo: 'rest.js',
  headers: {
    accept: 'application/vnd.github.mercy-preview+json'
  }
})

Multiple preview headers can be combined by separating them with commas

const {data: {topics, code_of_conduct}} = octokit.repos.get({
  owner: 'octokit',
  repo: 'rest.js',
  headers: {
    accept: 'application/vnd.github.mercy-preview+json,application/vnd.github.scarlet-witch-preview+json'
  }
})

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.
// basic
octokit.authenticate({
  type: 'basic',
  username: 'yourusername',
  password: 'password'
})

// oauth
octokit.authenticate({
  type: 'oauth',
  token: 'secrettoken123'
})

// oauth key/secret (to get a token)
octokit.authenticate({
  type: 'oauth',
  key: 'client_id',
  secret: 'client_secret'
})

// token (https://github.com/settings/tokens)
octokit.authenticate({
  type: 'token',
  token: 'secrettoken123'
})

// GitHub app
octokit.authenticate({
  type: 'integration',
  token: 'secrettoken123'
})

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

Pagination

There are a few pagination-related methods:

  • hasNextPage(response)
  • hasPreviousPage(response)
  • hasFirstPage(response)
  • hasLastPage(response)
  • getNextPage(response)
  • getPreviousPage(response)
  • getFirstPage(response)
  • getLastPage(response)

Usage

async function paginate (method) {
  let response = await method({per_page: 100})
  let {data} = response
  while (octokit.hasNextPage(response)) {
    response = await octokit.getNextPage(response)
    data = data.concat(response.data)
  }
  return data
}

paginate(octokit.repos.getAll)
  .then(data => {
    // handle all results
  })

Debug

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

Tests

Before running any tests you have to start the fixtures server

$ npm run start-fixtures-server

In a second terminal, run the tests

$ npm test

Or run a specific test

$ ./node_modules/.bin/mocha test/scenarios/get-repository-test.js

Run browser tests

$ npm run test:browser

Note: In order to run the same scenario tests in both Node and browser, we simulate the Cypress environment in Node, see test/mocha-node-setup.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

Current Tags

  • 21.0.0-beta.4                                ...           beta (6 months ago)
  • 15.18.1                                ...           deprecations-for-v16 (6 years ago)
  • 21.0.2                                ...           latest (4 months ago)
  • 15.18.3                                ...           release-15.x (5 years ago)
  • 16.43.2                                ...           release-16.x (5 years ago)
  • 17.11.0                                ...           release-17.x (5 years ago)
  • 18.12.0                                ...           release-18.x (3 years ago)
  • 19.0.13                                ...           release-19.x (2 years ago)
  • 20.1.0                                ...           release-20.x (9 months ago)

297 Versions

  • 21.0.2                                ...           4 months ago
  • 21.0.1                                ...           5 months ago
  • 21.0.0                                ...           6 months ago
  • 21.0.0-beta.4                                ...           6 months ago
  • 20.1.1                                ...           8 months ago
  • 21.0.0-beta.3                                ...           8 months ago
  • 21.0.0-beta.2                                ...           8 months ago
  • 20.1.0                                ...           9 months ago
  • 21.0.0-beta.1                                ...           10 months ago
  • 20.0.2                                ...           a year ago
  • 20.0.1                                ...           a year ago
  • 20.0.0                                ...           a year ago
  • 20.0.0-beta.5                                ...           a year ago
  • 20.0.0-beta.4                                ...           a year ago
  • 20.0.0-beta.3                                ...           a year ago
  • 19.0.13                                ...           2 years ago
  • 19.0.12                                ...           2 years ago
  • 20.0.0-beta.2                                ...           2 years ago
  • 20.0.0-beta.1                                ...           2 years ago
  • 19.0.11                                ...           2 years ago
  • 19.0.10                                ...           2 years ago
  • 19.0.9                                ...           2 years ago
  • 19.0.8                                ...           2 years ago
  • 19.0.7                                ...           2 years ago
  • 19.0.6                                ...           2 years ago
  • 19.0.5                                ...           2 years ago
  • 19.0.4                                ...           2 years ago
  • 19.0.3                                ...           2 years ago
  • 19.0.2                                ...           2 years ago
  • 19.0.1                                ...           2 years ago
  • 19.0.0                                ...           2 years ago
  • 18.12.0                                ...           3 years ago
  • 18.11.4                                ...           3 years ago
  • 18.11.3                                ...           3 years ago
  • 18.11.2                                ...           3 years ago
  • 18.11.1                                ...           3 years ago
  • 18.11.0                                ...           3 years ago
  • 18.10.0                                ...           3 years ago
  • 18.9.1                                ...           3 years ago
  • 18.9.0                                ...           3 years ago
  • 18.8.0                                ...           3 years ago
  • 18.7.2                                ...           3 years ago
  • 18.7.1                                ...           3 years ago
  • 18.7.0                                ...           3 years ago
  • 18.6.8                                ...           3 years ago
  • 18.6.7                                ...           3 years ago
  • 18.6.6                                ...           3 years ago
  • 18.6.5                                ...           3 years ago
  • 18.6.4                                ...           3 years ago
  • 18.6.3                                ...           3 years ago
  • 18.6.2                                ...           4 years ago
  • 18.6.1                                ...           4 years ago
  • 18.6.0                                ...           4 years ago
  • 18.5.6                                ...           4 years ago
  • 18.5.6-beta.1                                ...           4 years ago
  • 18.5.5                                ...           4 years ago
  • 18.5.4                                ...           4 years ago
  • 18.5.3                                ...           4 years ago
  • 18.5.2                                ...           4 years ago
  • 18.5.1                                ...           4 years ago
  • 18.5.0                                ...           4 years ago
  • 18.4.0                                ...           4 years ago
  • 18.3.5                                ...           4 years ago
  • 18.3.4                                ...           4 years ago
  • 18.3.3                                ...           4 years ago
  • 18.3.2                                ...           4 years ago
  • 18.3.1                                ...           4 years ago
  • 18.3.0                                ...           4 years ago
  • 18.2.1                                ...           4 years ago
  • 18.2.0                                ...           4 years ago
  • 18.1.1                                ...           4 years ago
  • 18.1.0                                ...           4 years ago
  • 18.0.15                                ...           4 years ago
  • 18.0.14                                ...           4 years ago
  • 18.0.13                                ...           4 years ago
  • 18.0.12                                ...           4 years ago
  • 18.0.11                                ...           4 years ago
  • 18.0.10                                ...           4 years ago
  • 18.0.9                                ...           4 years ago
  • 18.0.8                                ...           4 years ago
  • 18.0.7                                ...           4 years ago
  • 18.0.6                                ...           4 years ago
  • 18.0.5                                ...           4 years ago
  • 18.0.4                                ...           4 years ago
  • 18.0.3                                ...           4 years ago
  • 18.0.2                                ...           4 years ago
  • 18.0.1                                ...           4 years ago
  • 16.43.2                                ...           5 years ago
  • 18.0.0                                ...           5 years ago
  • 17.11.2                                ...           5 years ago
  • 17.11.1                                ...           5 years ago
  • 17.11.0                                ...           5 years ago
  • 17.10.0                                ...           5 years ago
  • 17.9.3                                ...           5 years ago
  • 17.9.2                                ...           5 years ago
  • 17.9.1                                ...           5 years ago
  • 17.9.0                                ...           5 years ago
  • 17.8.0                                ...           5 years ago
  • 17.7.0                                ...           5 years ago
  • 17.6.0                                ...           5 years ago
  • 17.5.2                                ...           5 years ago
  • 17.5.1                                ...           5 years ago
  • 17.5.0                                ...           5 years ago
  • 17.4.0                                ...           5 years ago
  • 17.3.0                                ...           5 years ago
  • 17.2.1                                ...           5 years ago
  • 17.2.0                                ...           5 years ago
  • 17.1.4                                ...           5 years ago
  • 17.1.3                                ...           5 years ago
  • 17.1.2                                ...           5 years ago
  • 17.1.1                                ...           5 years ago
  • 17.1.0                                ...           5 years ago
  • 17.0.1                                ...           5 years ago
  • 17.0.0                                ...           5 years ago
  • 17.0.0-beta.3                                ...           5 years ago
  • 17.0.0-beta.2                                ...           5 years ago
  • 16.43.1                                ...           5 years ago
  • 16.43.0                                ...           5 years ago
  • 16.42.2                                ...           5 years ago
  • 16.42.1                                ...           5 years ago
  • 16.42.0                                ...           5 years ago
  • 17.0.0-beta.1                                ...           5 years ago
  • 16.41.2                                ...           5 years ago
  • 16.41.1                                ...           5 years ago
  • 16.41.0                                ...           5 years ago
  • 16.40.2                                ...           5 years ago
  • 16.40.1                                ...           5 years ago
  • 16.40.0                                ...           5 years ago
  • 16.39.0                                ...           5 years ago
  • 16.38.3                                ...           5 years ago
  • 16.38.2                                ...           5 years ago
  • 16.38.1                                ...           5 years ago
  • 16.38.0                                ...           5 years ago
  • 16.37.0                                ...           5 years ago
  • 16.36.0                                ...           5 years ago
  • 16.35.2                                ...           5 years ago
  • 16.35.1                                ...           5 years ago
  • 16.35.0                                ...           5 years ago
  • 16.34.1                                ...           5 years ago
  • 16.34.0                                ...           5 years ago
  • 16.33.1                                ...           5 years ago
  • 16.33.0                                ...           5 years ago
  • 16.32.0                                ...           5 years ago
  • 16.31.0                                ...           5 years ago
  • 16.30.2                                ...           5 years ago
  • 16.30.1                                ...           5 years ago
  • 16.30.0                                ...           5 years ago
  • 16.29.0                                ...           5 years ago
  • 16.28.9                                ...           5 years ago
  • 16.28.8                                ...           5 years ago
  • 15.18.3                                ...           5 years ago
  • 15.18.2                                ...           5 years ago
  • 16.28.7                                ...           5 years ago
  • 16.28.6                                ...           5 years ago
  • 16.28.5                                ...           5 years ago
  • 16.28.4                                ...           5 years ago
  • 16.28.3                                ...           5 years ago
  • 16.28.2                                ...           6 years ago
  • 16.28.1                                ...           6 years ago
  • 16.28.0                                ...           6 years ago
  • 16.27.3                                ...           6 years ago
  • 16.27.2                                ...           6 years ago
  • 16.27.1                                ...           6 years ago
  • 16.27.0                                ...           6 years ago
  • 16.26.0                                ...           6 years ago
  • 16.25.6                                ...           6 years ago
  • 16.25.5                                ...           6 years ago
  • 16.25.4                                ...           6 years ago
  • 16.25.3                                ...           6 years ago
  • 16.25.2                                ...           6 years ago
  • 16.25.1                                ...           6 years ago
  • 16.25.0                                ...           6 years ago
  • 16.24.3                                ...           6 years ago
  • 16.24.2                                ...           6 years ago
  • 16.24.1                                ...           6 years ago
  • 16.24.0                                ...           6 years ago
  • 16.23.5                                ...           6 years ago
  • 16.23.4                                ...           6 years ago
  • 16.23.3                                ...           6 years ago
  • 16.23.2                                ...           6 years ago
  • 16.23.1                                ...           6 years ago
  • 16.23.0                                ...           6 years ago
  • 16.22.0                                ...           6 years ago
  • 16.21.1                                ...           6 years ago
  • 16.21.0                                ...           6 years ago
  • 16.20.0                                ...           6 years ago
  • 16.19.0                                ...           6 years ago
  • 16.18.1                                ...           6 years ago
  • 16.18.0                                ...           6 years ago
  • 16.17.1                                ...           6 years ago
  • 16.17.0                                ...           6 years ago
  • 16.16.5                                ...           6 years ago
  • 16.16.4                                ...           6 years ago
  • 16.16.3                                ...           6 years ago
  • 16.16.2                                ...           6 years ago
  • 16.16.1                                ...           6 years ago
  • 16.16.0                                ...           6 years ago
  • 16.15.1                                ...           6 years ago
  • 16.15.0                                ...           6 years ago
  • 16.14.1                                ...           6 years ago
  • 16.14.0                                ...           6 years ago
  • 16.13.4                                ...           6 years ago
  • 16.13.3                                ...           6 years ago
  • 16.13.2                                ...           6 years ago
  • 16.13.1                                ...           6 years ago
  • 16.13.0                                ...           6 years ago
  • 16.12.0                                ...           6 years ago
  • 16.11.0                                ...           6 years ago
  • 16.10.0                                ...           6 years ago
  • 16.9.0                                ...           6 years ago
  • 16.8.1                                ...           6 years ago
  • 16.8.0                                ...           6 years ago
  • 16.7.0                                ...           6 years ago
  • 16.6.1                                ...           6 years ago
  • 16.6.0                                ...           6 years ago
  • 16.5.0                                ...           6 years ago
  • 16.4.0                                ...           6 years ago
  • 16.3.2                                ...           6 years ago
  • 16.3.1                                ...           6 years ago
  • 16.3.0                                ...           6 years ago
  • 15.18.1                                ...           6 years ago
  • 16.2.0                                ...           6 years ago
  • 16.1.0                                ...           6 years ago
  • 16.0.5                                ...           6 years ago
  • 16.0.4                                ...           6 years ago
  • 16.0.3                                ...           6 years ago
  • 16.0.2                                ...           6 years ago
  • 16.0.1                                ...           6 years ago
  • 16.0.0                                ...           6 years ago
  • 15.18.0                                ...           6 years ago
  • 15.17.0                                ...           6 years ago
  • 15.16.1                                ...           6 years ago
  • 15.16.0                                ...           6 years ago
  • 15.15.1                                ...           6 years ago
  • 15.15.0                                ...           6 years ago
  • 15.14.0                                ...           6 years ago
  • 15.13.1                                ...           6 years ago
  • 15.13.0                                ...           6 years ago
  • 15.12.1                                ...           6 years ago
  • 15.12.0                                ...           6 years ago
  • 15.11.4                                ...           6 years ago
  • 15.11.3                                ...           6 years ago
  • 15.11.2                                ...           6 years ago
  • 15.11.1                                ...           6 years ago
  • 15.11.0                                ...           6 years ago
  • 15.10.0                                ...           6 years ago
  • 15.9.6                                ...           6 years ago
  • 15.9.5                                ...           6 years ago
  • 15.9.4                                ...           6 years ago
  • 15.9.3                                ...           6 years ago
  • 15.9.2                                ...           7 years ago
  • 15.9.1                                ...           7 years ago
  • 15.9.0                                ...           7 years ago
  • 15.8.2                                ...           7 years ago
  • 15.8.1                                ...           7 years ago
  • 15.8.0                                ...           7 years ago
  • 15.7.0                                ...           7 years ago
  • 15.6.2                                ...           7 years ago
  • 15.6.1                                ...           7 years ago
  • 15.6.0                                ...           7 years ago
  • 15.5.1                                ...           7 years ago
  • 15.5.0                                ...           7 years ago
  • 15.4.1                                ...           7 years ago
  • 15.4.0                                ...           7 years ago
  • 15.3.0                                ...           7 years ago
  • 15.2.7                                ...           7 years ago
  • 15.2.6                                ...           7 years ago
  • 15.2.5                                ...           7 years ago
  • 15.2.4                                ...           7 years ago
  • 15.2.3                                ...           7 years ago
  • 15.2.2                                ...           7 years ago
  • 15.2.1                                ...           7 years ago
  • 15.2.0                                ...           7 years ago
  • 15.1.9                                ...           7 years ago
  • 15.1.8                                ...           7 years ago
  • 15.1.7                                ...           7 years ago
  • 15.1.6                                ...           7 years ago
  • 15.1.5                                ...           7 years ago
  • 15.1.4                                ...           7 years ago
  • 15.1.3                                ...           7 years ago
  • 15.1.2                                ...           7 years ago
  • 15.1.1                                ...           7 years ago
  • 15.1.0                                ...           7 years ago
  • 15.0.4                                ...           7 years ago
  • 15.0.3                                ...           7 years ago
  • 15.0.2                                ...           7 years ago
  • 15.0.1                                ...           7 years ago
  • 14.0.9                                ...           7 years ago
  • 14.0.8                                ...           7 years ago
  • 14.0.7                                ...           7 years ago
  • 14.0.6                                ...           7 years ago
  • 14.0.5                                ...           7 years ago
  • 14.0.4                                ...           7 years ago
  • 14.0.3                                ...           7 years ago
  • 14.0.2                                ...           7 years ago
  • 14.0.1                                ...           7 years ago
  • 14.0.0                                ...           7 years ago
Downloads
Total 4
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (29)

© 2010 - cnpmjs.org x YWFE | Home | YWFE