Getting File Content using GIT Hub API

The GIT Hub itself has a fairly complete tutorial for accessing GIT hub uploaded files.

https://developer.github.com/v3/

However, I think it can still use some little extra explanation.

Make sure you get the following steps right for this:

  • Depending upon master/branch, get your URL for the repository ready first.
  • Next, get the correct header inserted into your HTTP request.
  • Make sure you are requesting data in ‘jsonp’ format
  • Extracting the content of your response can also get tricky. make sure to look into ‘data.contents’ value.
  • Finally, decode the encoded content.

Here’s my implementation API call:


var gitURL = 'https://api.github.com/';
var gitAPIServiceOptions = {
url: gitURL + yourGitHubFilePath,
requestType: "GET",
dataType: "JSONP",
httpHeader: 'Accept',
headerValue:'application/vnd.github.v3.raw+json',
callBack: function(result) {
if (result.success === true) {
var decodedResult = atob(result.data.data.content) ;
}
}
};

Thanks!

Tags: