Understanding HTTP - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts


HTTP (HyperText Transfer Protocol) is a standard application-level protocol that supports the communication between client and server on World Wide Web (www) through TCP port 80.

In general, HTTP is a very standardized way of how a client and server communicate with each other. Beyond the scope of establishing the communication, computer systems can deliver the data like text, images, HTML files, query results, etc along with HTTP. Hence HTTP can be thought of as a protocol that establishes the connection between two machines and delivers the data.

If machine A wants to communicate with machine B, then machine A has to initiate an HTTP request to machine B, and in return, machine B will respond to this request by initiating an HTTP response for machine A. Both the HTTP request and response can carry data alongside.


Features of HTTP


  • HTTP is Connectionless - When a client initiates an HTTP request for a server, the server receives it and as soon as the request is received, the client gets disconnected from the server saving huge computing resources. As long as the server serves the request, the disconnected client waits for the response. When the server initiates the response once again the connection gets established, and as soon as the client receives the response, the connection once again breaks. This essentially means that HTTP does not block itself during the service of the request.

  • HTTP is Stateless - Every time a client makes a request to the server, the server takes it as a new request and just after serving it, it does not remember for which client it has just served. Even if the same client makes a second request, still the server would take it as a fresh request as it does not store the client information.

  • HTTP is Media Neutral - The client and the server can deliver any sort of data with HTTP. HTTP abstracts the data leaving its media type and carries the content only. As long as the client and the server are able to handle the data content, the data would be delivered seamlessly by HTTP.


HTTP Request


HTTP Request is sent by the client for the server as the client-server connection starts from the client side. This contains much useful information among which the following needs special mention
  • Requested URI - It represents the URI (Unified Resource Identifier) of the servlet that has to be accessed. Though there are some differences between URI and URL, you can take it very loosely as the address of the servlet.
  • Request Method and Content - Request Method represents the method that has to be called on the requested URI, that is on the servlet. It also carries the content that is being delivered by HTTP.

Different HTTP request methods


  1. GET - Requests the server to get the resource at the requested URI. It does not modify any server resources.
  2. POST - Requests the server to submit the processed resource at the requested URI. Through POST you can submit some data to the server so that the server can modify one or some of its resource(s) depending upon the data that you have posted.
  3. HEAD - Requests a server (just like GET) to get the resource at the requested URI, but it does not receive the returned resource. The difference between the GET and HEAD is like the following:
    The GET method requests for a resource and actually receives the resource, whereas HEAD requests for a resource but actually do not receive it. Head is generally used before the GET just to examine the nature of the requested resource so that consequent business logic can be applied accordingly
  4. TRACE - Requests the server to echo the received request. It is used for confirming whether a server is receiving the requests as per business logic or not.
  5. PUT- Requests the server (like the POST method) to modify a server resource at the specified URI depending upon the data you have put. The difference of it with POST is like following:
    Repeated PUT request will always give you the same result but repeated POST might give different results depending upon the request. It essentially means that PUT is idempotent whereas POST is non-idempotent.
  6. DELETE - Requests a server to delete a specified resource at the specified URI.
  7. OPTION - Requests a server to return data that essentially describes the other methods and operations supported at the requested URI.

Difference between the GET and POST


The two most common HTTP request methods are GET and POST. Here are some fundamental differences between these two
  • GET requests never modify any resources at the requested URI but POST methods modify or update resources at the requested URI.
  • GET requests are idempotent whereas POST requests are non-idempotent. This means that multiple GET requests will give you the same data whereas multiple POST requests can result in different data.
  • GET requests have a restriction on the data length that can be sent to the server. The URL should be 2048 bytes at the max. On the other hand, POST requests have no data length restrictions.
  • You can only send ASCII characters with GET; whereas, with POST, you can send any binary data.
  • GET is lesser safe as the data is carried along with the URL and hence is exposed. POST carries the data as an object. Hence a POST method is safer than the GET method.
Hope these discussions have boosted you up to dive deep into Web Application Development.

No comments:

Post a Comment