Thoa Shook
3 min readMay 12, 2020

Working with APIs

A web service allows different systems to talk to each other over the internet. These systems can be any combination of devices or applications. They can be windows, Linux, or mobile phones. A web API is part of a website designed to interact with programs. These programs use very specific URLs to request information, and the request, itself, is called an API call. The request data will be returned in a form of json or csv. Most apps that rely on external data sources such as apps that integrate with social media websites rely heavily on API calls.

Requesting data using an API call

You can request information on GitHub through the use of API calls. For example, if I wanted to obtain information about the most popular Python repositories on GitHub, I would enter the request -an API call into my browser’s address bar and press enter.

This is an API call — A Request

https://api.github.com/search/repositories?q=language:python&sort=stars

  1. The first part https://api.github.com/ directs the request to the part of GitHub that responds to API calls.
  2. The ‘search/repositories’, tells the API to conduct a search through all repositories on GitHub.
  3. The ‘?’ signals the beginning of an argument.
  4. The ‘q’ stands for query : q =
  5. The ‘language:python’ indicates that we want repositories that are written in Python only.
  6. The ‘sort=stars’ sorts the projects by the number of stars they’ve been given.

This is the snippet of the Response

There are 5,249,425 repositories that are written in Python on GitHub. The request was successful because the ‘incomplete_results’ is false. If the API call was unsuccessful, the ‘incomplete_results’ would have returned true. The list ‘items’ contains details about the most popular Python projects on GitHub. The first element of the ‘item’ list is a dictionary.

Processing an API Response through code

  1. Import requests
  2. Make an API call and store the response

url =’https://api.github.com/search/repositories?q=language:python&sort=stars

headers = {‘Accept’: ‘application/vnd.github.v3+json’}

r = requests.get(url, headers=headers)

print(f”Status code: {r.status_code}”)

3. Store API response in a variable

response_dict = r.json()

4. Process results

print(response_dict.keys())

Because the status code is 200, we know that the request was successful. The response is a dictionary with three keys: total_count, incomplete_results, and items.

Explore Information about the response dictionary

  1. The number of repositories on GitHub is associated with the key: total_count in the response dictionary

print(f”Total repositories: {response_dict[‘total_count’]}”)

2. The ‘items’ is another key of the response_dict. The value associated with ‘items’ It is a list that contains a number of dictionaries, each dictionary contains data about an individual python repository.

repo_dict_itmes= response_dict[‘items’]

print(f”Repositories returned: {len(response_dict_items)}”)

3. Examine the first element — dictionary on the items list and discovery its keys

Repo_dict_item = repo_dict_items[0]

print(f”\nKeys: {len(repo_dict_item)}”)

for key in sorted(repo_dict_item.keys()):

print(key)

GitHub returns a lot of information about each repository. There are 74 keys in the repo_dict_item. Dig deeper into these keys gives us all kinds of information that you want to know about a project. Let’s check it out.

This project is about learning how to design large-scale systems. Prepare for the system design interview which includes Anki flashcards. The project has been starred by 94,764 GitHub users. It was created on 02/26/2017 and the most recent update is on 05/12/20. Donne Martin is the owner of this project.

API Rate Limits

Most APIs are rate limits meaning that you can only make a number of requests in a period of time. There is an URL to check for the rate limits on GitHub such as https://api.github.com/rate_limit.