Internet — Behind the scenes
Hi friends, I am Yashvardhan Kukreja and I am a Full Stack Android developer. Around one year ago, after learning to implement readymade APIs (like yahoo weather API, news API etc. ) while developing apps, I realised how cool it would be if I could code my own APIs or if I could have a dedicated userbase using an app coded by me. Then, I decided to start learning back end development in MEAN stack.
Initially, I faced problems while learning Back End Dev because most of the online tutorials and examples were provided assuming that the learner is quite well versed with Front end Web Dev becasue the online tutorials were teaching AngularJS alongside which was linked with Front End Web Dev. Somehow I learnt NodeJS and MongoDB (For Database Management) through a project based example of building a very basic login and signup system.
But still, I wasn’t satisfied because I used to feel that I just mugged up the code instead of understanding the logic behind each and every line of code. The problem with back end is that you can’t SEE back end because back end doesn’t have a Graphical Interface involved like front end dev. So, I was feeling it hard to imagine how the things were working after the back end code gets compiled.
So, I realised that before starting to code back end, I have to understand how internet works with reference to a successfully compiled back end code.
So, I will be writing about the basics which will help you a lot if you want to start learning back end dev. I will be using relevant analogies and examples to make sure that the respective concepts are conveyed as clear as possible. So, let’s start.
What is internet? (A difficult question indeed XD)
So, INTERNET is an incredibly massive web of requests and responses being transmitted over different computers each and every second.
So, before moving on further, I would like to explain some terminologies and buzzwords that would help you understanding the rest of the article.
- Server — A computer in a network which provides functionalities to it’s clients. In very simple words, if you run a back end code on your computer, then technically, your computer can also be called a server because then, your computer will be capable of providing functionalities to all the other computers (clients) in the same network. Fun Fact: Actually, Server is not a computer or any hardware, it’s a program which runs on a computer to provide a variety of services to its clients. The computer on which a server runs is called host. Although I will be using Server as a computer in the article because I feel that it will be easier to explain things as most of the people and online resources relate server to a computer.
- Database — An organized collection of data. A database can be a computer or even an excel sheet.
- Cloud — Condensed water vapours suspended at high altitudes in the sky. Sorry, kidding XD. Cloud is, actually, a data center containing tons of servers where each of them is capable of providing incredible computing power.
- Intranet — A private network usually set up by an organisation for undergoing all of its operations private from the public. It’s like an organisation own internet.
Now, let’s proceed with the internet.
Basically, what ever you do on internet is a kind of request you make to the internet (servers) and the internet (servers) gives you the response accordingly. For example, by typing www.google.com in the search bar of your browser and hitting Enter key, you are, basically, making a request to the internet to get directed to the above URL i.e. www.google.com. Now, the internet checks if www.google.com exists or not and after checking that it will respond accordingly. For www.google.com, internet will realise that it is an existing website which can be used by public, so, it will link the browser to the homepage of google.com as a response. If you type a random non-existing website like www.djfndjfknsdfb.com, then Internet will realise that you made an irrelevant request for a non-existing website and hence, it will respond by displaying a message like “ This website doesn’t exist”.
So, majorly, there are four types of requests a user makes on the browser :-
- GET request — This is a kind of request you make when you want to fetch something from the internet. For example, whenever you type websites like, www.google.com, www.github.com etc. You are making GET request to the internet for getting these websites on your browser.
- POST request — As the name suggests, this is a kind of request you make when you want to post something on the internet. For example, while logging in into your Facebook account, you are making a POST request because you’re sending your username and password to the internet. Then, the internet (Facebook Server and Database in this case) checks the username-password combination and responds accordingly with messages like “Logged in successfully”, “Wrong Password” or “Username doesn’t exists”. Even when you are messaging someone or even making a google search, you are making a POST request because you are sending some data to the internet (servers).
- PUT request — This is a kind of request you make when you want to edit something on the internet. PUT request puts data on the internet if it doesn’t exist on the internet or overwrites the data if it already exists on the internet (which is basically, editing data). For instance, let’s assume you want to change your name on Facebook. So, you go to profile settings and type a different name there and when you press ENTER, you make a PUT request to the internet which then, overwrites your current name on Facebook and thereby, edits it.
- DELETE request — This is a kind of request you make when you want to delete/remove something from the internet. For example, if you want to delete a pic from facebook timeline, you go on the menu and click the “Delete” option. By doing so, you make a DELETE request for that pic and hence, it gets deleted.
While coding back end, the functionalities being performed by GET, PUT and DELETE can be made to be performed by POST request alone itself. But it’s unconventional to do that. So, being a good developer, you should code conventionally.
There are other types of requests as well but majorly, the above four types of requests are performed.
Now, Internet doesn’t understand whether the response for the request made by the user is feasible or unfeasible. So, there are some numerical codes which make the internet understand what’s the status of the request being made. These numerical codes are knows as HTTP Status Codes. When you try to enter a non-existing website in the browser’s search bar, you get a response like “Error 404, Not Found !!”. In such kind of case, the HTTP Status Code is 404.
There a lot of status codes but they are also conventional based on the response. You can understand the type of response without even knowing the details of the exact response code.
- Status codes like 1xx :- Any status code ranging from 100 to 200 (not including 200) means that it’s an informational response. It, basically, alerts when something happens while processing a request. For example, while making a POST request, two things are sent to the server i.e. Headers and Response Body. So, first of all, headers are sent and when they are received on the server, the server replies with a 100 status code stating that headers have reached and now, send the request body and then, the request body is sent. You won’t see this kind of status code while browsing because these kind of status codes are usually used while experimentation.
- Status codes like 2xx :- Any status code ranging from 200 to 300 (not including 300) means that it’s a successful response. For example, when you enter an existing website’s name in the search bar, you get a 200 status code meaning SUCCESS and then, the website get launched in the browser.
- Status codes like 3xx :- Any status code ranging from 300 to 400 (not including 400) means that it will take some extra action(request) to successfully complete the required request. For example, if you type www.fb.com in the browser’s search bar, then the facebook servers will return a 3xx kind of status code and behind the scenes, an additional request for www.facebook.com will be made in the browser automatically and finally, www.facebook.com will be launched. You might see a 200 status code but that status code will be corresponding the response of the additional request being made automatically by facebook servers, in this case.
- Status codes like 4xx :- Any status code ranging from 400 to 500 (not including 500) means that there is a client side error. In simple words, the user made a unfeasible request by his/her mistake. For example, 404 means that the requested resource is not found. 401 means that the user is unauthorized to make the given request.
- Status codes like 5xx :- Any status code ranging from 500 to 600 (not including 600) means that is a server side error. For example, let’s assume, that on new year, every FB user tried to post something on FB. So, due to such a massive number of requests (due to the massive userbase), facebook might crash. And if would have opened FB in such situation, you will receive a response with a status of 5xx kind meaning that there is a problem with FB.
You can get the list of all the HTTP Status Codes with their respective descriptions here => https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
I hope this article was well descriptive and you understood the concepts conveyed by it. Still, if you face any difficulties or problems with any of the above concepts, I would love to resolve it. Just drop me a mail :)
E-mail — yash.kukreja.98@gmail.com
Github — https://github.com/Yashvardhan-Kukreja
LinkedIn — https://www.linkedin.com/in/yashvardhan-kukreja-607b24142/