在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:brunolemos/react-native-github-api开源软件地址:https://github.com/brunolemos/react-native-github-api开源编程语言:JavaScript 92.1%开源软件介绍:rest.js
UsageNodeInstall with const octokit = require('@octokit/rest')()
// Compare: https://developer.github.com/v3/repos/#list-organization-repositories
octokit.repos.getForOrg({
org: 'octokit',
type: 'public'
}).then(({ data, headers, status }) => {
// handle data
}) Browser
Client optionsAll available client options with default values const octokit = require('@octokit/rest')({
timeout: 0, // 0 means no request timeout
headers: {
accept: 'application/vnd.github.v3+json',
'user-agent': 'octokit/rest.js v1.2.3' // v1.2.3 will be current version
},
// custom GitHub Enterprise URL
baseUrl: 'https://api.github.com',
// Node only: advanced request options can be passed as http(s) agent
agent: undefined
})
API PreviewsTo take advantage of GitHub’s API Previews,
pass a custom 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, codeOfConduct } } = octokit.repos.get({
owner: 'octokit',
repo: 'rest.js',
headers: {
accept: 'application/vnd.github.mercy-preview+json,application/vnd.github.scarlet-witch-preview+json'
}
}) AuthenticationMost GitHub API calls don't require authentication. Rules of thumb:
// 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: 'app',
token: 'secrettoken123'
}) Note: PaginationThere are a few pagination-related methods:
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
}) DebugSet TestsBefore running any tests you have to start the 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 ContributingWe would love you to contribute to Credits
LICENSE |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论