simple-github-api
This is a simple wrapper for the GitHub API to ease requesting files, directory information from a repository.
Basic Usage:
# To download and install npm install --save simple-github-api
const API = let instance = // https://github.com/blog/1509-personal-api-tokens token: "Some valid OAUTH key issued by github" // choose your repo, or you can omit this option and set it later repo: "myProject" // the username/owner of the repo(s) username: "markzuckerberg" instance // OR instance
API
const API =
Constructors
The new
keyword is required to
create an instance of the API
object.
It is recommended to get an OAUTH
key issued for your application and
instantiate with that token.
let instance = token: "A valid token"
The default object however doesn't require any config.
// results in a warning.// If you do > 60 requests per day// you will get a 401 error for api requests.let instance =
You can also pass in basic auth credentials, and a repository.
// all valid options you can pass inoptions = username: "jeff" pw: "secret" repo: "sweetProject" // token will override basic auth if provided token: "OAUTHToken"
Main Features
The basic interface below is unlikely to change, although further features may be added later. For all of the below path is a string.
Interface | Description |
---|---|
.get(path) |
Returns the fileObject or directory for the relevant file. Takes a string relative path, and requires the repo and user to be set. |
.getUrl(path) |
Returns the current url formed for the request. Mainly called internally. |
.getContents(path) |
Returns the file contents directly, decoded and ready to use. |
.decode(encodedFile) |
Decodes a file object in base64Unicode. |
Configuration
// sets/update a new repoinstancerepo = "NewRepo" // sets/update userinstanceuser = "newUser" // returns the underlying axios instance// which you can configure as you so desire// More on axios here https://github.com/axios/axioslet axios = instanceaxios
Credits
Project built leaning heavily on the simplicity of the axios api.
License
MIT