An Analogy to better understand HTTP Requests
↕
It can be tricky to understand how HTTP functions because it’s difficult to examine what your browser is actually doing. (And perhaps also because we explained it using acronyms that may be new to you.) Let’s review what we learned by using an analogy that could be more familiar to you.
Imagine the internet is a town. You are a client and your address determines where you can be reached. Businesses in town, such as Codecademy.com, serve requests that are sent to them. The other houses are filled with other clients like you that are making requests and expecting responses from these businesses in town. This town also has a crazy fast mail service, an army of mail delivery staff that can travel on trains that move at the speed of light.
Suppose you want to read the morning newspaper. In order to retrieve it, you write down what you need in a language called HTTP and ask your local mail delivery staff agent to retrieve it from a specific business. The mail delivery person agrees and builds a railroad track (connection) between your house and the business nearly instantly, and rides the train car labeled “TCP” to the address of the business you provided.
Upon arriving at the business, she asks the first of several free employees ready to fulfill the request. The employee searches for the page of the newspaper that you requested but cannot find it and communicates that back to the mail delivery person.
The mail delivery person returns on the light speed train, ripping up the tracks on the way back, and tells you that there was a problem “404 Not Found.” After you check the spelling of what you had written, you realize that you misspelled the newspaper title. You correct it and provide the corrected title to the mail delivery person.
This time the mail delivery person is able to retrieve it from the business. You can now read your newspaper in peace until you decide you want to read the next page, at which point, you would make another request and give it to the mail delivery person.
Source:
https://www.codecademy.com/articles/http-requests
</div>
New Vocabulary
# HTTP stands for “Hypertext Transfer Protocol .” It’s a set of rules for how
computers ask each other for content, and how they reply.JSON stands for JavaScript Object Notation . It is the standard file format for exchanging data over the internet. The syntax mimics dictionaries by using key
and value
pairs.API stands for Application Programming Interface . It is software that allows computers to communicate with each other. An API
often provides JSON
.[0] HTTP GET
# Every time you visit a URL, your computer opens a connection with the server at that address and uses HTTP to send and recieve the content.
GET Request
# Communication starts when one computer (the client) sends a request to another computer (the server). For example, by visiting “cs.fablearn.org” you initiate
a GET
request to recieve the Making with Code homepage from the server.
A GET
request contains following:
GET Response
# Once the request has been recieved by the server, it responds by sending the client a HTTP response . If a successful connection has been made, the server sends the content to the client.
Here’s an example of a HTTP response to a successful GET
request to the course website:
1
2
3
4
5
6
7
8
9
10
11
12
13
HTTP/1.1 200 OK // This is the response
Content-Length: 2081 // I am sending a lot
Content-Type: text/html // I am sending HTML
Date: Tue, 18 Aug 2020 19:23:28 GMT // This is when I sent it
Last-Modified: Tue, 18 Aug 2020 15:46:28 GMT // There is new content
<!DOCTYPE html> // Here it comes!
<html lang= "en" > // Here is your webpage
. . .
<p><em>Making with Code</em> is a new, old
approach to teaching computer science
based in Constructionism.</p>
. . .
200
(line 1) is the response status code.Content-Length
(line 2), Content-Type
(line 3), Date
(line 4), and Last-Modified
(line 5) are response headers. They provide
more detail about what is being requested and what is being sent back. For example, the Content-Type
tells your computer what
type of data is being recieved. For “cs.fablearn.org”, your computer recieves the HTML, Javacsript, CSS, and image files that make
up the homepage of the site.<!DOCTYPE html>
(line 7) is the beginning of the content sent with the response. This is the HTML of the course website which your
browser then renders as a webpage.Status Codes
# Status codes are used to signal how the communication between the client and the server is going.
Common HTTP Status Codes
200
means success.300
means you’re looking in the wrong place304
means there’s no new content since you last came to this page400
means you did something wrong.404
means the resource requested could not be found500
means, “Sorry, the server broke!”Using HTTPIE
# ✅ CHECKPOINT:
Complete the section, the-isf-academy.github.io/making-with-code
, of the worksheet. You will need to:
Right click and click “Inspect” Select “Network” from the top toolbar in the developer tools Hard refresh the page with “Command + Shift + R” [2] API: DATA.GOV.HK
# DATA.GOV.HK hosts open data provided by the Hong Kong government. It provides an open APIs
that allows anyone to access their databases. We are going to use HTTP Requests
to access this database.
API
stands for Application Programming Interface . It is software that allows computers to communicate with each other. An API
often provides JSON
.
✈️ In this lab, we will look at the data for the HK International Airport
JSON
# JSON stands for JavaScript Object Notation . It is the standard file format for exchanging data over the internet. The syntax mimics dictionaries by using key
and value
pairs.
For example, this is JSON
for the HK International Airport. What is the JSON describing?
[
{
"date" : "2025-08-01" ,
"arrival" : true,
"cargo" : true,
"list" : [
{
"time" : "00:00" ,
"flight" : [
{
"no" : "ET 3684" ,
"airline" : "ETH"
}
] ,
"status" : "Cancelled" ,
"statusCode" : null,
"origin" : [
"LGG" ,
"KGF"
]
} ,
...
}
]
Notice how it looks exactly like a dictionary with key
and value
pairs.
Making HTTP Requests
# This lab will require you to make a series of http requests
to the HKO API.
💻 Go to
httpie.io/app . You will use this web app to send HTTP requests.
💻 Make a simple http get
request to recieve JSON
from DATA.GOV.HK.
GET
- tells the app you are making a get
requesthttps://www.hongkongairport.com/flightinfo-rest/rest/flights/past
- tells the app which address you’d like to make the request todate: 2025-08-01
- tells the date you want is August 1st, 2025✅ CHECKPOINT:
💻 Open the flight API documentation from DATA.GOV.HK:
API Documentation . You will need to utilize this resource complete the worksheet.
✏️ Complete the section, 1. DATA.GOV.HK API
, of the worksheet to further explore http requests
, JSON
, and APIs
.
[3] Deliverables
# ⚡✨ Once you’ve successfully completed the worksheet be sure to fill out
this Google form .
[4] Extension
# Now that you’ve had succifient practice accessing APIs, it’s time to explore what type of APIs exist.
💻 Explore an API of your choosing.
You may want to use the httpie
Terminal commands. Here are some suggestions of APIs to explore: