The Internet may be humanity’s most profound invention. A global
network of computers talking to one another, making it possible for people all
over the world to interact. In this lab, we will start learning about how
computers talk with one another.
A. The Basic Rules of HTTP
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.
Requests
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 / HTTP/1.1
Host: cs.fablearn.org
An HTTP GET request
Another frequently utilized request is a POST request. A POST Request is sent when you are sending data to the server. For example, logging into an account or making an online purchase.
In the POST request below, the webpage would contain a form to recieve the user’s data.
POST / HTTP/1.1
Host: social_media_login.com
An HTTP POST request
Responses
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.
An HTTP response
Status Codes
Status codes are used to signal how the communication between the client and the server is going.
π» To see status codes in action:
Right click on any website and click “Inspect”
Select “Network” from the top tool bar in the devleoper tools
Hard refresh your page with “Command + Shift + R”
Find the URL under “Name”
Under the “Status” column you will see “200”, signifiying a sucessful GET request
πΎ π¬ FYI
All actions on the Internet are composed of HTTP Requests.
Every time you access a website, it triggers a series of HTTP Requests depending on its complexity.
Every time a client requests information from a server, the request is recorded along with the status code.