# @gr2m/octokit-rest-browser-experimental

> GitHub REST API client for Node.js

Latest version **16.1.2** (published 2018-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @gr2m/octokit-rest-browser-experimental
pnpm add @gr2m/octokit-rest-browser-experimental
yarn add @gr2m/octokit-rest-browser-experimental
bun add @gr2m/octokit-rest-browser-experimental
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 16.1.2 |
| Published | 2018-02-15 |
| First published | 2018-01-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 8 |
| Unpacked size | 551.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gregor Martynus |
| Maintainers | gr2m |
| Keywords | octokit, github, rest, api-client |

## Links

- npm: https://www.npmjs.com/package/@gr2m/octokit-rest-browser-experimental
- Repository: https://github.com/gr2m/octokit-rest-browser-experimental
- Homepage: https://github.com/gr2m/octokit-rest-browser-experimental#readme
- Issues: https://github.com/gr2m/octokit-rest-browser-experimental/issues
- npm.io page: https://npm.io/package/@gr2m/octokit-rest-browser-experimental

## Dependencies (8)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [btoa-lite](https://npm.io/package/btoa-lite.md) ^1.0.0
- [is-stream](https://npm.io/package/is-stream.md) ^1.1.0
- [url-template](https://npm.io/package/url-template.md) ^2.0.8
- [is-array-buffer](https://npm.io/package/is-array-buffer.md) ^1.0.0
- [before-after-hook](https://npm.io/package/before-after-hook.md) ^1.1.0
- [@octokit/fixtures-server](https://npm.io/package/@octokit/fixtures-server.md) ^2.0.1

## 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

- 16.1.2 (latest) — 2018-02-15
- 16.0.0-debug-bundlephobia.1 (bundlephobia) — 2018-02-02
- 16.1.1 — 2018-02-15
- 16.1.0 — 2018-02-03
- 16.0.0-debug-bundlephobia.0 — 2018-02-02
- 16.0.0 — 2018-02-02
- 15.1.0 — 2018-02-02
- 15.0.1 — 2018-01-26
- 15.0.0 — 2018-01-25

## README

# Temporary fork [octokit/rest.js](https://github.com/octokit/rest.js) with browser-support

This fork is work-in-progress exploration towards [Browser Support for `@octokit/rest`](https://github.com/octokit/rest.js/milestone/2).

## Browser usage

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

2. Load it as script into your web application:

   ```html
   <script scr="octokit-rest.min.js"></script>
   ```

3. Initialize `octokit`

   ```js
   const octokit = new Octokit()
   ```

## Breaking changes

The endpoint methods like `octokit.repos.get()` are generated from the
[lib/routes.json](lib/routes.json) file, which is used. The internal
implementation already moved it into a plugin so we take advantage of that now.
Instead of loading these plugins by default:

- [authentication](lib/plugins/authentication)
- [endpoint-methods](lib/plugins/endpoint-methods)
- [pagination](lib/plugins/pagination)

You will now have to load them manually, like so

```js
const octokit = require('@gr2m/octokit-rest-browser-experimental')()
// add octokit.authenticate() method
octokit.plugin(require('@gr2m/octokit-rest-browser-experimental/lib/plugins/authentication'))

// add endpoint methods
octokit.plugin(require('@gr2m/octokit-rest-browser-experimental/lib/plugins/endpoint-methods'))

// add pagination methods
octokit.plugin(require('@gr2m/octokit-rest-browser-experimental/lib/plugins/pagination'))
```

## Testing in Node & Browser

All tests in the [test/](test) folder are run in Node. All tests in the
[test/scenarios/](test/scearios) folder are also run in the browser with
[cypress](https://www.cypress.io).

Before running the tests you need to start the fixtures server which the tests
are using as a drop-in replacement for GitHub's API

1. Start fixtures server with `npm run start-fixtures-server`
2. In a 2nd terminal, run `npm test` for Node or `npm run test:browser` for Browser
3. Once you are done, stop the fixtures server in the 1st terminal with ctrl + c

---

> GitHub REST API client for Node.js

[![Build Status](https://travis-ci.org/gr2m/octokit-rest-browser-experimental.svg?branch=master)](https://travis-ci.org/gr2m/octokit-rest-browser-experimental)
[![Coverage Status](https://coveralls.io/repos/github/gr2m/octokit-rest-browser-experimental/badge.svg)](https://coveralls.io/github/gr2m/octokit-rest-browser-experimental)
[![Greenkeeper](https://badges.greenkeeper.io/gr2m/octokit-rest-browser-experimental.svg)](https://greenkeeper.io/)
[![npm](https://img.shields.io/npm/v/@gr2m/octokit-rest-browser-experimental.svg)](https://www.npmjs.com/package/@gr2m/octokit-rest-browser-experimental)

## Usage

Install with `npm install @gr2m/octokit-rest-browser-experimental`.

<!-- HEADS UP: when changing the options for the constructor, make sure to also
     update the type definition templates in scripts/templates/* -->
```js
const octokit = require('@gr2m/octokit-rest-browser-experimental')()

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

All available client options with default values

```js
const octokit = require('@gr2m/octokit-rest-browser-experimental')({
  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: 433,

  // advanced request options
  // see https://nodejs.org/api/http.html
  proxy: undefined,
  ca: undefined,
  rejectUnauthorized: undefined,
  family: undefined
})
```

`@gr2m/octokit-rest-browser-experimental` API docs: https://octokit.github.io/rest.js/  
GitHub v3 REST API docs: https://developer.github.com/v3/

## 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.

```javascript
// 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

```js
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

Run all tests

```bash
$ npm test
```

Or run a specific test

```bash
$ ./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.

## Contributing

We would love you to contribute to `@gr2m/octokit-rest-browser-experimental`, pull requests are very welcomed!
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

## Credits

`@gr2m/octokit-rest-browser-experimental` was originally created as [`node-github`](https://www.npmjs.com/package/github)
in 2012 by Mike de Boer from Cloud9 IDE, Inc.
It was adopted and renamed by GitHub in 2017

## LICENSE

[MIT](LICENSE)

---
_Source: https://npm.io/package/@gr2m/octokit-rest-browser-experimental · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
