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
- Host: GitHub
- URL: https://github.com/scriptex/universal-github-client
- Owner: scriptex
- License: mit
- Created: 2020-06-15T13:23:57.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-04-10T01:26:17.000Z (about 2 months ago)
- Last Synced: 2025-04-10T04:05:21.335Z (about 2 months ago)
- Topics: github-api, github-api-v3, github-client
- Language: TypeScript
- Homepage: https://atanas.info/portfolio/open-source/universal-github-client
- Size: 3.47 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.com/scriptex/universal-github-client)
[](https://github.com/scriptex/universal-github-client/actions?query=workflow%3ABuild)
[](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)
[](https://codebeat.co/projects/github-com-scriptex-universal-github-client-master)
[](https://www.codefactor.io/repository/github/scriptex/universal-github-client)
[](https://deepscan.io/dashboard#view=project&tid=3574&pid=5257&bid=40799)
[](https://github.com/scriptex/universal-github-client/)# Universal Github Client
> A Github API Client for the browser and Node JS
## Visitor stats



## Code stats




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