How to get a file through the GitHub API

I need to get the contents of a file hosted in a GitHub repository. I would rather get a JSON response with metadata along with it. I tried a lot of urls using cURL to get the answer {"message":"Not Found"}. I just need a URL structure. If that matters, it's from an organization on GitHub. Here, what I think should work, but does not:

http://api.github.com/repos/<organization>/<repository>/git/branches/<branch>/<file>
+5
source share
1 answer

As a description (located at http://developer.github.com/v3/repos/contents/ ) it says:

/ repo /: owner /: repo / content /: path

The ajax code will be:

$.ajax({
    url: readme_uri,
    dataType: 'jsonp',
    success: function(results)
    {
        var content = results.data.content;
    });

Replace readme_uri with the correct / repos /: owner /: repo / contents /: path.

+11
source

All Articles