Simple GitHub API wrapper for node.js
Lots of times you don't need a full-fledged GitHub API client with authentication and what-not. Maybe you just want to load public data, or index and process your public repositories somehow. This simple GitHub API 'wrapper' provides the basics and can access all non-restricted API end points. And it's easily extendable too!
The wrapper loads a JSON file (routes.json
) which contains a name space, a method name and an end point URI. Together, all methods are dynamically created at startup-time. This makes it very easy to add new end points in the future. The library makes use of promises through request-promise.
Currently not all suitable end points have been added. You can either wait for me to add them to routes.json
, or you can do it yourself (and submit a pull request, of course! ;)).
Install
npm install github-api-simple
Usage
const SimpleApi = ;let api = ; // takes an options argument, see below simpleApiRepositories ;
The constructor takes an options argument, which is fed to request-promise. The defaults are:
const DEFAULT_OPTIONS = 'baseUrl': 'https://api.github.com' 'headers': 'User-Agent': 'github-api-simple v' + pkgversion + ' [nodejs] [https://github.com/MichielvdVelde/github-api-simple]' 'json': true;
You can change the User-Agent
header to set your own, the GitHub API requires one.
Routes
Users
Single user
All route methods take an optional options
object as the last argument. This object is extend()
-ed with the options you gave when usig new
. For example, if you want to get all your repositories sorted by when it was last pushed to, you can:
let options = 'qs': 'sort': 'pushed' 'direction': 'desc' // optional, GitHub API uses 'desc' by default for 'pushed' simpleApiUsers ;
simpleApiUsers ;
All users
simpleApiUsers ;
Repositories
Repositories for a single user
simpleApiRepositories ;
Single repository
simpleApiRepositories ;
Contributors
simpleApiRepositories ;
Languages
simpleApiRepositories ;
Teams
simpleApiRepositories ;
Tags
simpleApiRepositories ;
Branches
simpleApiRepositories ;
Single branch
simpleApiRepositories ;
Contents of a repository file
simpleApiRepositories ;
Repository commits
simpleApiRepositories ;
Repository single commit
simpleApiRepositories ;
Followers
Get followers for user
simpleApiFollowers ;
Get followers by user
simpleApiFollowers ;
Issues
Get issues for repository
simpleApiIssues ;
Get a single issue
simpleApiIssues ;
Get issue comments
simpleApiIssues ;
Get issue comments
simpleApiIssues ;
Get issue comment
simpleApiIssues ;
Milestones
Get all milestones for a repository
simpleApiMilestones ;
Get a single milestone
simpleApiMilestones ;
To do
- Add the rest of the applicable API end points to the routes file
- Add paging support
- Make rate limiting headers available
- Write some tests
Changelog
- 0.1.0 - 25 October 2017
- Drop fs and .readFileSync() to support Browserify (thanks to jywarren)
- 0.0.4 - 0.0.5 10 December 2015
- (0.0.6) Added
Repositories.getRepoCommits()
andRepositories.getRepoCommit()
- (0.0.5) Added
Repositories.getRepositoryFile(username, reponame, filename)
- (0.0.4) Added a lot of new end points to
routes.json
- (0.0.4) Fixed some readme mistakes
- (0.0.6) Added
- 0.0.1 - 0.0.3 - 9 December 2015
- (0.0.3) Improved readme
- (0.0.2) Moved
routes.json
to dirassets
- (0.0.2) Fixed stupid-ass path error
- (0.0.1) Initial commit
License
Copyright 2015 Michiel van der Velde.
This software is licensed under the MIT License.