HTTP Request — Response Cycle, a Letter in the Mail (pt.1)

Mike del Rio
Mar 1, 2019 · 5 min read
Image for post
Image for post
Photo by Brian Patrick Tagalog on Unsplash

You’ve been connected to the internet since the day you were born and may be wondering how does this internet thing work? Maybe you know that an IP address has something to do with websites knowing what country you’re located in and are likely familiar with typing a website’s address (URL) into a browser. That was the extent of my knowledge about being online and was recently blown away after being introduced to the basic mechanisms at work that allow us to exchange information instantaneously across the world. Let’s take a very zoomed out view of the process that allows us to interact with the web, a basic HTTP response/request cycle (more on that in a moment). The web is the content (resources) you access online such as text and images and the internet is a number of network connections that allow you to access these resources.

Hopefully you’re old fashioned enough to be familiar with sending a letter in the mail. This will serve as our analogy. The letters being sent back and forth will represent HTTP request-response cycles. We won’t go into details about HTTP, just know that it represents a set of rules/protocols that allow devices to speak to each other in order to exchange information over the internet. Thankfully browsers don’t require us to enter http:// or https:// before the rest of the URL anymore. What’s the difference between HTTP and HTTPS? HTTPS operates similarly to HTTP however the messages being sent and received are wrapped in a layer of encryption. That way if someone intercepted messages going to or coming from your computer they would not be able to read the content of those messages.

Most of us are familiar with accessing websites through a browser. We enter a URL and information magically appears on our screen. However you can also interact with the web via another type of application: an HTTP tool. An exchange of HTTP messages is all that’s occurring when you use a browser and different applications allow this exchange to occur. The most user-friendly way to send and receive HTTP messages with the purpose of interacting with web resources remains through a browser.

There are two main types of HTTP messages that are used to interact with the web: GET and POST. GET and POST are HTTP methods. A GET method is used to request resources from a server. When you type a URL into a browser a GET request is performed. A POST method involves sending information to a server. Completing and sending a form on a website will result in a POST method call.

This is the first of a two part series of articles, we’ll first look at how a request is sent and arrives at its destination. The next article will go over the response part of the cycle.

Image for post
Image for post

Here’s how you might imagine your letter, complete with a sender and a receiver (no stamp required because using the internet is free!).

Image for post
Image for post

Let’s start to sharpen our model: you, the client, want to access a resource from a website. The content of this website is found on a server (or many servers but let’s keep it to one). The hostname is the website’s name that you would put in your browser: , this URL’s hostname is nba.

Image for post
Image for post

Now instead of written names, the details about where the letter is coming from and where it’s going take the form of sockets. A socket is the combination of an IP address and a port. The IP address is like your home address and the port can be thought of as where you expect to find your mail (say specifying that a mailbox is found on the side vs the front door). The port is where the server can receive incoming messages. If a message is addressed to the right IP address of a server but the port number is wrong, the server won’t ‘see’ the message. A web server’s port is usually 443, the default port for HTTPS messages.

Image for post
Image for post

Now our letter has addresses truly fit for the internet. We haven’t mailed our letter yet but we already have the address of the host. How could this be? Maybe you’ve memorized the IP address of your favorite website? In a browser we’re familiar with typing in a hostname. Once that HTTP request enters the network it is translated to the recipient server’s IP address via DNS (Domain Name System). If you know the recipient’s IP address you could enter it directly in the URL instead of the website’s name.

A bit more information on our addresses. Currently a slow transition is occurring between two kinds of IP address versions: IPV4 (as seen on our letter’s sender address) and IPV6 (as seen on our letter’s receiver address). Just like phone numbers eventually have to change in a region (by adding different area codes) as the population grows you can think of the same thing happening with the internet. More people are getting connected to the internet everyday and all the variations of IPV4 addresses will eventually be taken. As you can see on our letter a IPV6 (128 bits) address contains more information than a IPV4 address (32 bits).

Let’s head off to the mailbox. Wait! There’s nothing in our letter. That’s okay as long as we simply want to request information from a web page’s server (a HTTP GET method). But what if we’re sending information to the server (a HTTP POST method). Well in that case we’ll tuck a letter in our envelope to send to the server (say our username and password for the site).

That’ll do for now. If you want to start filling in your knowledge gaps I recommend some reading related to the following: URL components, HTTP, DNS.

Ready for part two?

Photo by Annie Spratt on Unsplash

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store