Dot Net For All

HTTP verbs and other Web basics

In this article I will discuss about the HTTP verbs which are basically GET, PUT , POST and DELETE along with the other HTTP basics which we should be aware of while working with web resources like what the various parts of the URL consists of. Along with that I will also show how request and response are generally made and what are the commonly used HTTP status codes.

As we know when we browse some website in the web browser like internet explorer or chrome we have to type in some URL which will ultimately take us to some address on the server and return back the content for the requested URL.

In the below figure I have shown the parts of the URL

Now while working with ASP.NET MVC or webapi we will most commonly see the URL in the below formats

Both of these are the formats which the client sends to the server to receive some data in response to the query string parameters. The URl path is made of the two or three parts names Noun ,verbs and parameters. The first part of the URL path is Noun which is the name of Controller if we talk about ASP.NET MVC framework which is the Customer in our example defined above. It is generally preferable to set the name of the controller as Noun and not the verb as it denotes the entity on which we are working on. The second part is the verb which is GetCustomer in our above example and third part is of course the parameters. The verbs denote the actions in the controllers.

Apart from the custom verbs or actions in the controllers there are four major type of HTTP verbs which I want to discuss here. Every request from the client to the server is made of one of these verbs.

In the below figure I have capture a request to my blog which I intercepted using the fiddler.

and the response for the same can be seen in the below figure

 

HTTP Verbs

In the first figure we can see an request issued by the client where GET is the primary HTTP method, each and every request should have one of these methods. Following are the commonly used HTTP methods along with their usages-

  1. GET – Retrieve the resource. This is a safe method which only lets us to view and read on the web resource. This method is used to read data from the data source like in case of search operations.
  2. POST – Update a resource. This request are generated by the form element on the page with the method=”POST”. This method is unsafe method as it let us to change the resource on web server. This method is used to update the onformation like updating the credit card information or any other information to data source
  3. PUT – Store a resource
  4. DELETE – Remove a resource.

PUT and DELETE are never used in web applications. These methods are only used in web services.

The format of the request message is [method][URL][version]

[headers]

[body]

one of the header which we should be aware of is the accept header

Accept Header is used to specify the preferred media type. It tells server what file formats, or more correctly MIME-types, the client is looking for.

Similarly in the response there is a header known as content type which represents what type of data is contained by our request.

Now as shown in the second figure for the response we have a status code . In the below figure I have mentioned some of the commonly received status code.

I hope this article will give you some basic understanding about the HTTP basics.

 

Top career enhancing courses you can't miss

My Learning Resource

Excel your system design interview