Next: Media types, Up: REST API Overview [Index]
Learn how to navigate the resources provided by the GitHub API.
This describes the resources that make up the official GitHub REST API.
By default, all requests to https://api.github.com receive the v3 version of the REST API. We encourage you to explicitly request this version via the ‘Accept’ header.
Accept: application/vnd.github.v3+json
YYYY-MM-DDTHH:MM:SSZ
When you fetch a list of resources, the response includes a subset of the attributes for that resource. This is the "summary" representation of the resource.
Example: When you get a list of repositories, you get the summary representation of each repository.
GET /orgs/octokit/repos
When you fetch an individual resource, the response typically includes all attributes for that resource. This is the "detailed" representation of the resource.
Example: When you get an individual repository, you get the detailed representation of the repository.
GET /repos/octokit/octokit.rb
There are two ways to authenticate through GitHub REST API.
$ curl -u "username" https://api.github.com
$ curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com
OAuth2 tokens can be acquired using the web application flow for production applications.
Many API methods take optional parameters.
$ curl -i "https://api.github.com/repos/vmg/redcarpet/issues?state=closed"
$ curl -i -u username -d '{"scopes":["public_repo"]}' https://api.github.com/authorizations
You can issue a ‘GET’ request to the root endpoint to get all the endpoint categories that the REST API supports:
$ curl -u username:token https://api.github.com
API v3 uses HTTP redirection where appropriate. Clients should assume that any request may result in a redirection. Receiving an HTTP redirection is not an error and clients should follow that redirect.
Permanent redirection.
Temporary redirection.
Ditto
Where possible, API v3 strives to use appropriate HTTP verbs for each action.
Can be issued against any resource to get just the HTTP header info.
Used for retrieving resources.
Used for creating resources.
Used for updating resources with partial JSON data.
Used for replacing resources or collections.
Used for deleting resources.
Requests that return multiple items will be paginated to 30 items by default.
You can specify further pages with the ‘page’ parameter.
For some resources, you can also set a custom page size up to 100 with the ‘per_page’ parameter.
Note that for technical reasons not all endpoints respect the ‘per_page’ parameter, see ‘events’ for example.
$ curl 'https://api.github.com/user/repos?page=2&per_page=100'
All API requests MUST include a valid ‘User-Agent’ header. Requests with no ‘User-Agent’ header will be rejected.
User-Agent: Awesome-Octocat-App
cURL
sends a valid ‘User-Agent’ header by default
Most responses return an ‘ETag’ header.
Many responses also return a ‘Last-Modified’ header.
You can use the values of these headers to make subsequent requests to those resources using the:
$ curl -i https://api.github.com/user -H 'If-None-Match: "644b5b0155e6404a9cc4bd9d8b1ae730"'
$ curl -i https://api.github.com/user -H "If-Modified-Since: Thu, 05 Jul 2012 15:31:30 GMT"
headers, respectively.
If the resource has not changed, the server will return a ‘304 Not Modified’.
Making a conditional request and receiving a 304 response does not count against your ‘Rate Limit’, so we encourage you to use it whenever possible.
The API supports Cross Origin Resource Sharing (CORS) for AJAX requests from any origin.
You can send a ‘?callback’ parameter to any ‘GET’ call to have the results wrapped in a JSON function. This is typically used when browsers want to embed GitHub content in web pages by getting around cross domain issues. The response includes the same data output as the regular API, plus the relevant HTTP Header information.
Next: Media types, Up: REST API Overview [Index]