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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
GitHub REST API client for Node.js
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/
Most GitHub API calls don't require authentication. Rules of thumb:
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.
There are a few pagination-related methods:
hasNextPage(response)
hasPreviousPage(response)
hasFirstPage(response)
hasLastPage(response)
getNextPage(response)
getPreviousPage(response)
getFirstPage(response)
getLastPage(response)
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
Set DEBUG=octokit:rest*
for additional debug logs.
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.
We would love you to contribute to @octokit/rest
, pull requests are very welcomed!
Please see CONTRIBUTING.md for more information.
@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