CodeBlanks Logo Icon CodeBlanks

REST API

Learn programmatic access with the GitHub REST API.

What is the GitHub REST API?

The GitHub REST API lets you interact with repositories, users, issues, and other GitHub resources through HTTP requests. You can perform operations programmatically instead of doing them manually in a browser.

GET https://api.github.com/repos/octocat/Hello-World

API responses are usually in JSON format. Each resource has a specific endpoint.

Endpoints and HTTP responses

An endpoint is a URL path used to access a specific resource through an API. For example, the /repos/{owner}/{repo} path is used for repository information.

GET /repos/octocat/Hello-World

200 OK
{
  "name": "Hello-World",
  "private": false
}

HTTP status codes indicate the result of a request. 200 means success, 404 means the resource was not found, and 401 can indicate an authentication problem.

Practice Create a GitHub API request

Create a GET request to retrieve information about the octocat/Hello-World repository. Assign the URL to the api_url variable and send the request with curl. Also display the HTTP response status code.

Starter code

terminal
# API adresini değişkene ata
# GET isteğini ve HTTP durum kodunu göster

Sample solution

terminal
api_url="https://api.github.com/repos/octocat/Hello-World"
curl -sS -o /dev/null -w "%{http_code}\n" -X GET "$api_url"

Expected output

200

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 You want to retrieve repository information through an HTTP request. Which HTTP method is suitable?

  • DELETE
  • GET Correct answer
  • PATCH
  • POST

Explanation: The GET method is used to read a resource through an API.

2 Complete the repository endpoint

Question
GET https://api.github.com/repos/____
Answer
GET https://api.github.com/repos/octocat/Hello-World

Explanation: A repository endpoint contains the owner's username and the repository name.

3 REST API components

Term Meaning
Endpoint Address used to access a resource
GET Reads resource data
JSON Common response data format
HTTP status Indicates the request result

All lessons in Expert