Introduction to HTTP basics

Communication is the core of human life, without it people will not be able to exchange ideas and interact with each other. There are set of rules followed for proper communication example harmony between listener and speaker. Similar set of rules is followed in world of Internet. In coming paragraphs we will be discussing the basic rule of internet called HTTP (Hyper text transfer protocol). Protocol is set of rules followed for specific purpose.

We will quickly test the above by using a site called httpbin.org that has number of endpoints for testing http requests/responses. We will dive more into this later.

We will be using telnet that is command that allows access to data on websites using  command line.

Steps to test http request:

      1. Open up your terminal
      2. type in telnet httpbin.org 80
      3. type in GET / HTTP/1.1
      4. type in  HOST:httpbin.org quickly and press ENTER key twice
      5. We will get the html that is located at / (root)

Terminals don’t have layout engine like browsers, so they are not capable of converting html to layout. If we enter httpbin.org we will see the html content in better layout.

Screen Shot 2018-01-11 at 4.41.02 PM

 

 

 

 

 

 

 

 

We can access any endpoints available example for viewing xml we can use /xml instead of / in above command.

HTTP Requests:

A basic HTTP request consists of Request line, Headers , Black line and Request Body.

As we know request can be either GET or POST.

we need to pass uri (uniform resource identifier) and HTTP version we are using as seen in below example:

Screen Shot 2018-01-15 at 4.29.12 PM

Headers consist of HOST name, User Agent we are using for sending request and Accepted Language.

Screen Shot 2018-01-15 at 4.32.55 PM.png

Next is a simple blank line and Request body which is applicable only for POST request.

In request body we pass PAYLOAD (data) along with POST request eg we need to pass some data to a particular form we can achieve that by POST request and sending data in Request Body.

Screen Shot 2018-01-15 at 4.33.43 PM.png

 

HTTP Response’s:

Http Response also has some important parts like:

Status-line:

This consists of Http version, status code and status message. There are lot of status code’s like 200 which means everything is fine, 404 which means resource or page is not available example if we type in http://www.abc.com/blah and if /blah is not available then we may get 404 error message and then we server error 500 code also. You can get more details on web about all the status code.

Each status code has some message called status message associated with it example 200 has OK message while as 404 has not available message associated.

Screen Shot 2018-01-15 at 4.40.46 PM

 

Response Headers: 

These usually consist if Server name like nginx or apache, Date on which response was received and Content type. In this case we have content of type xml while we can have html type also.

Screen Shot 2018-01-15 at 4.42.17 PM

Blank Line and Response body:

After a blank line we get actual response in the form of Response Body.

Screen Shot 2018-01-15 at 4.43.03 PM

Note : HTTP Protocol is Stateless. This means it does’nt remember or it does’nt keep the record of previous request. 

 

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s