1.0.0 • Published 8 years ago

ghify-request-options v1.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

ghify-request-options

NPM version Build Status Coverage Status devDependency Status

Create a Request option object that helps to interact with the GitHub API

const ghifyRequestOptions = require('ghify-request-options');

ghifyRequestOptions({method: 'POST'});
/* => {
	 method: 'POST',
	 json: true,
     headers: {
       accept: 'application/vnd.github.v3+json',
       'user-agent': 'https://github.com/shinnn/ghify-request-options'
     },
     baseUrl: 'https://api.github.com'
   }
*/ 

Installation

Use npm.

npm install ghify-request-options

API

const ghifyRequest = require('ghify-request-options');

ghifyRequestOptions(options)

options: Object (Request options to overwrite the defaults, and token option)
Return: Object (new Request options)

It returns Request options that defaults to the GitHub-API-friendly settings.

ghifyRequestOptions();
/* => {
	 json: true,
     headers: {
       accept: 'application/vnd.github.v3+json',
       'user-agent': 'https://github.com/shinnn/ghify-request-options'
     },
     baseUrl: 'https://api.github.com'
   }
*/ 

options.token

Type: String
Default: process.env.GITHUB_TOKEN

Use specific GitHub access token.

ghifyRequestOptions({
  token: 'xxxxxxxxxxx' // your personal access token
});
/* => {
     json: true,
     token: 'xxxxxxx',
     headers: {
       accept: 'application/vnd.github.v3+json',
       'user-agent': 'https://github.com/shinnn/ghify-request-options',
       authorization: 'token xxxxxxxxxxx'
     },
     baseUrl: 'https://api.github.com'
   }
*/

options.baseUrl

Type: String
Default: process.env.GITHUB_ENDPOINT if available, otherwise 'https://api.github.com'

Use the different endpoint to support Github enterprise.

License

Copyright (c) 2015 Shinnosuke Watanabe

Licensed under the MIT License.