An open API service indexing awesome lists of open source software.

https://github.com/scriptex/universal-github-client

A Github API Client for the browser and Node
https://github.com/scriptex/universal-github-client

github-api github-api-v3 github-client

Last synced: about 2 months ago
JSON representation

A Github API Client for the browser and Node

Awesome Lists containing this project

README

        

[![Travis CI](https://travis-ci.com/scriptex/universal-github-client.svg?branch=master)](https://travis-ci.com/scriptex/universal-github-client)
[![Github Build](https://github.com/scriptex/universal-github-client/workflows/Build/badge.svg)](https://github.com/scriptex/universal-github-client/actions?query=workflow%3ABuild)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/34d3d75710534dc6a38c3584a1dcd068)](https://www.codacy.com/gh/scriptex/universal-github-client/dashboard?utm_source=github.com&utm_medium=referral&utm_content=scriptex/universal-github-client&utm_campaign=Badge_Grade)
[![Codebeat Badge](https://codebeat.co/badges/d765a4c8-2c0e-44f2-89c3-fa364fdc14e6)](https://codebeat.co/projects/github-com-scriptex-universal-github-client-master)
[![CodeFactor Badge](https://www.codefactor.io/repository/github/scriptex/universal-github-client/badge)](https://www.codefactor.io/repository/github/scriptex/universal-github-client)
[![DeepScan grade](https://deepscan.io/api/teams/3574/projects/5257/branches/40799/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=3574&pid=5257&bid=40799)
[![Analytics](https://ga-beacon-361907.ew.r.appspot.com/UA-83446952-1/github.com/scriptex/universal-github-client/README.md?pixel)](https://github.com/scriptex/universal-github-client/)

# Universal Github Client

> A Github API Client for the browser and Node JS

## Visitor stats

![GitHub stars](https://img.shields.io/github/stars/scriptex/universal-github-client?style=social)
![GitHub forks](https://img.shields.io/github/forks/scriptex/universal-github-client?style=social)
![GitHub watchers](https://img.shields.io/github/watchers/scriptex/universal-github-client?style=social)
![GitHub followers](https://img.shields.io/github/followers/scriptex?style=social)

## Code stats

![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/scriptex/universal-github-client)
![GitHub repo size](https://img.shields.io/github/repo-size/scriptex/universal-github-client?style=plastic)
![GitHub language count](https://img.shields.io/github/languages/count/scriptex/universal-github-client?style=plastic)
![GitHub top language](https://img.shields.io/github/languages/top/scriptex/universal-github-client?style=plastic)
![GitHub last commit](https://img.shields.io/github/last-commit/scriptex/universal-github-client?style=plastic)

## Installation and getting started

First install the package

```sh
npm i universal-github-client

# or

yarn add universal-github-client
```

Then you need to generate a new token from your [Github profile](https://github.com/settings/tokens) and make sure that this token has access to the relevant scopes that you plan to query the API for.

Then you need to configure and setup your Github Client instance:

### In Node

Node prior to v17.5.0 and v16.5.0 does not include the `fetch` API so you might need to install a polyfill in order to use this module in Node.

```sh
npm i node-fetch

# or

yarn add node-fetch
```

Node v16.5.0 and v17.5.0 include the `fetch` API but behind the `--experimental-fetch` CLI flag.

Node v18.0.0 no longer requires the `--experimental-fetch` CLI flag but the `fetch` API is still marked as "experimental".

Node v21.0.0 comes with a stable version of the `fetch` API.

More about the history of the `fetch` API and its usage in Node can be found [in the official documentation](https://nodejs.org/docs/latest/api/globals.html#fetch).

```javascript
const fetch = require('node-fetch');
const { GithubClient } = require('universal-github-client');

const client = new GitHubClient({
base: 'https://api.github.com',
token: 'YOUR_GITHUB_TOKEN_HERE',
fetch
});
```

### In browser

Please note that this package is supported by browsers which implement natively the Fetch API and have support for Promises.
If you are using an outdated browser, you need to install a polyfill for Fetch and Promises.

```javascript

import { GithubClient } = from 'universal-github-client';

const client = new GitHubClient({
base: 'https://api.github.com',
token: 'YOUR_GITHUB_TOKEN_HERE',
fetch
});
```

## Usage

When you have installed and configured the `client`, you can make calls to the [Github API](https://developer.github.com/v3/):

You can use the paths defined in the [Github API](https://developer.github.com/v3/) documentation.

For example, if you want to [get the repositories](https://developer.github.com/v3/repos/#list-repositories-for-a-user) for a user you need to do the following:

```javascript
const repos = client.get({ path: '/users/scriptex/repo' }); // scriptex is the Github user name
```

There are five different instance methods based on the HTTP method required by a particular endpoint in the Github API.

```javascript
client.get({ path });

client.post({ path, data });

client.delete({ path });

client.put({ path, data });

client.patch({ path, data });
```

## LICENSE

MIT

---


Connect with me:






 



 



 



 



 



 



 



 



 



 



 



---


Support and sponsor my work: