HTTP

HTTP is a protocol used by computers to communicate with each other.
A protocol is just a series of rules/steps which need to be followed for communication.
e.g. If you want to buy a chocolate from the mall, you can go to the mall,
find the chocolate put it in a shopping cart, go to the checkout counter and pay the bill.
This can be thought of as a protocol, In this example, the steps are not very strict,
but in computer protocols there is no scope for ambiguity.

HTTP is used whenever you visit a website. HTTP lays out the rules the
communication between your browser and the web server. Here is an example of
what happens when you open enter cosmicvent.com in your browser and hit enter:

1) The browser finds the IP address of cosmicvent.com (which at the moment is 176.9.113.5).
2) It sends it a text message using another protocol called TCP/IP. The message
looks something like this:

This is called an HTTP ‘Request’, It says that the browser is ‘making’ a ‘GET’
request using the ‘HTTP/1.1’ protocol and that the browser is looking for a
‘document’ called ‘/‘ of type ‘html’ or ‘xhtml’. The ‘User-Agent’ has information about
the version of the browser.

3) Now, the webserver which is the software running on google sends an HTTP
‘Response’ which looks like the following:

Now this text is understood by the browser, the browser reads the header which
is the part above the empty line (above <!doctype html>). The response says
that the server is also using the ‘HTTP/1.1’ protocol, the 200 and OK mean
that the response was ‘successful’ and it didn’t fail (The 200 is a status
code, and HTTP has many status codes with different meanings, you might have
seen 404 Not found in a browser, that means the document requested by the
browser could not be found by the webserver). It also tells us when this
document was sent, and some more information which is understood by the
server. Another important Header is the ‘Content-Type’ which tells the browser
what type of document the response is. In this example it says the content
type is an html document. So, the browser renders it as an html page. If the
content type was an image, the response would have something like: ‘Content-Type: image/png’,
which would tell the browser to render it as an image. What follows after the
empty line (the <!doctype html>…) is the actual content.

An analogy for an HTTP Response is a mail package. The cover of the mail package has
information about the package like the weight of the package, the address to
which it is to be delivered, its contents. And when you open the package it
contains the actual items. An HTTP response is similar but it has different
information in the ‘Header’ (the package wrapping). This information is
sometimes also called meta data. And, the actual document comes after an empty
line after the header.