# gh-get

> Create a request to the Github API

Latest version **1.1.0** (published 2017-01-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install gh-get
pnpm add gh-get
yarn add gh-get
bun add gh-get
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-01-12 |
| First published | 2015-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Shinnosuke Watanabe |
| Maintainers | shinnn |
| Keywords | request, https, wrapper, api, github, github-api, gh, promise, promises, then, thenable, class, get, put, patch, post, head, delete |

## Links

- npm: https://www.npmjs.com/package/gh-get
- Repository: https://github.com/shinnn/gh-get
- Homepage: https://github.com/shinnn/gh-get#readme
- Issues: https://github.com/shinnn/gh-get/issues
- npm.io page: https://npm.io/package/gh-get

## Dependencies (2)

- [fettuccine](https://npm.io/package/fettuccine.md) ^1.0.2
- [ghify-request-options](https://npm.io/package/ghify-request-options.md) ^1.0.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2017-01-12
- 1.0.2 — 2017-01-12
- 1.0.1 — 2015-12-30
- 1.0.0 — 2015-12-29

## README

# gh-get

[![NPM version](https://img.shields.io/npm/v/gh-get.svg)](https://www.npmjs.com/package/gh-get)
[![Build Status](https://travis-ci.org/shinnn/gh-get.svg?branch=master)](https://travis-ci.org/shinnn/gh-get)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/gh-get.svg)](https://coveralls.io/github/shinnn/gh-get?branch=master)
[![Dependency Status](https://david-dm.org/shinnn/gh-get.svg)](https://david-dm.org/shinnn/gh-get)
[![devDependency Status](https://david-dm.org/shinnn/gh-get/dev-status.svg)](https://david-dm.org/shinnn/gh-get#info=devDependencies)

A [Node.js](https://nodejs.org/) module to create a request to the [Github API](https://developer.github.com/v3/)

```javascript
const ghGet = require('gh-get');

ghGet('users/isaacs', {userAgent: 'your application name'}).then(response => {
  response.body.login; //=> 'isaacs'
});
```

## Installation

[Use npm.](https://docs.npmjs.com/cli/install)

```
npm install gh-get
```

## API

```javascript
const ghGet = require('gh-get');
```

### ghGet(*url* [, *options*])

*url*: `String` ("path" part of a Github API URL)  
*options*: `Object`  
Return: [`Promise`](https://promisesaplus.com/)

It makes a `GET` request to the [Github API](https://developer.github.com/v3/#overview) and returns a promise. Request method is overridable with the `method` [option](https://github.com/shinnn/gh-get#options).

When the API request finishes successfully, the promise will be [*fulfilled*](https://promisesaplus.com/#point-26) with the  [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_http_incomingmessage) object with the additional `body` property that contains a JSON object of the API response.

#### Options

You can use [`Request` options](https://github.com/request/request#requestoptions-callback) and the following.

##### options.userAgent

Type: `String` (GitHub username or the name of your application)  

[Required](https://developer.github.com/v3/#user-agent-required). Add `user-agent` to the request header.

##### options.token

Type: `String`  
Default: `process.env.GITHUB_TOKEN`

Use specific [GitHub access token](https://github.com/blog/1509-personal-api-tokens).

```javascript
ghGet('user', {
  token: 'xxxxx' //=> for example @shinnn's access token
  userAgent: 'Shinnosuke Watanabe https://github.com/shinnn/'
}).then(response => {
  response.body.login; //=> 'shinnn'
});
```

##### options.verbose

Type: `Boolean`  
Default: `false`

`true` adds an [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_http_incomingmessage) object to the error message as `response` property.

```javascript
ghGet('user/repos', {token: 'invalid_token'}).then(err => {
  err.message; //=> '401 Unauthorized (Bad credentials)'
  'response' in error; //=> false
});

ghGet('user/repos', {
  token: 'invalid_token',
  verbose: true
}).then(err => {
  err.message; //=> '401 Unauthorized (Bad credentials)'
  err.response; //=> {statusCode: 401, body: { ... }, headers: { ... }, ...}
});
```

##### options.baseUrl

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

Use the different root [endpoint](https://developer.github.com/v3/#root-endpoint) to support [Github enterprise](https://enterprise.github.com/).

## License

Copyright (c) 2015 - 2017 [Shinnosuke Watanabe](https://github.com/shinnn)

Licensed under [the MIT License](./LICENSE).

---
_Source: https://npm.io/package/gh-get · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
