Sat, Feb 6, 2021
Read in 6 minutes
While the internet may look like a complicated machine from the outside, its richness inside is powered by variations of the same few HTTP protocols.
You will learn the basics of HTTP and process HTTP requests using a simple web application.
The basic model of the internet is based on a request. Almost everything on the internet is exchanged using a few standard HTTP methods:
As the name suggests,
get is an action where you retrieve information from a location in the internet. You have been using
get for as long as you have started surfing the internet. Some examples:
getrequest to get the website contents and displaying on your device.
getrequest to fetch the news feed contents.
Get also allows you to get slightly different versions of a website by using *query param*eters. As an example, if you put
https://www.bing.com/search?q=best+sushi into your browser task bar, Bing will automatically find results for the keyword
best sushi. (more on this in exercises below.)
Get is typically only used as a way to fetch and not change a resource. For that you need to use
Post is another very common action that is used to make changes to a resource. Without you knowing, you have also been using
post behind the scenes for:
postrequest to Instagram’s server for processing.
Post requests are also special in that they are securely transmitted in the form of form parameters. When using in conjunction with secure HTTPS, it keeps the contents encrypted between the origin (your browser or app) and the destination.
No matter the type of request, whether
POST, the protocol requires there be a response. You may be familiar with the dreaded
404 Not Found when you try to access something that is missing online. Apart from
404 there are many more codes; some of the common ones are
302for redirection to another link.
400bad request. This indicates a problem on the request. There was information sent to the destination that the destination did not prepare for.
500server error. This indicates a problem on the destination. Perhaps the server crashed when processing a request midway.
Status codes are usually accompanied by a response body. Example, for browsers you almost never see 200 ever printed on the page because a successful
200 almost always accompanies the page content you requested for.
In the most severe of cases if there is no response, then it becomes a
timeout error. You may have encountered this if you tried to shop on a very busy E-commerce site when the entire site ground to a halt.
This is where web applications come in!
Web applications open themselves to receiving requests from the internet. Every time a request is received, the application will:
The application takes these information and does the processing accordingly and then determines the correct type of response and response body to return back to the origin.
As you move from page to page, and swipe along your app, you are really just making requests upon requests to get the content you need.
Of course the internet is made up of more complicated protocols for other media like:
But for starters, knowing just how to make and respond to HTTP requests can get you started making really interactive websites!
This module will require a lot of self reading. However, if you are stuck anywhere, feel free to ping me! Google and YouTube will be your best friend.
Let’s look under the hood of the web browser!
There are tons of tutorials out there for starting up a basic web application for the language of your choice. Pick one one get started!
You’ll want to install
node first on your computer before proceeding to starting a new Express.js application
For any of these options, you may run into operating system specific errors. For these you’ll want to try searching for answers online first on how to resolve them.
Once you manage to install the basic application, start the server and make your first web request by going to the home page.
Once you have managed to access the sample page, look at the logs (usually on the same Terminal page that you started the logs) and try to make sense of it. Specifically, look for
Reading logs will go a long way to help you figure out what went wrong when making changes to your application.
Let’s try to make your application a little more dynamic: Modify the function that handles the sample route so that it prints whatever you set on the URL params.
Example: when you access
http://localhost:3000/?message=my+message, make it show “my message” on the browser.
?message=hellothat is added to the back of the URL. These give your application able to respond dynamically.
Learning to write software? Subscribe now to receive tips on software engineering.