HTTP Request Methods

Headers are basically the metadata that is sent by the client and server while communicating with each other. It contains 

  • HTTP Method,
  • Connection type, 
  • User-Agent, 
  • HTTP Version, 
  • Content-Encoding, 
  • Host, etc.

Request and Response both contain headers that may differ. For example, Content-Length, while requesting may be less or null (might not be even present) in the request header while in the response header,   the content length parameter is present.

The first line in the request headers contains the HTTP Method, Host, and HTTP Version which is sent to the server for processing, after processing the server responds with the response header and the content.

Types of HTTP Methods

There are 8 types of methods GET, POST, HEAD, PUT, DELETE, OPTIONS, CONNECT, and TRACE

  • GET: The GET method is used to retrieve data from a given server using a URI (Uniform Resource Identifier).  Requests using the GET method only retrieve data and have no other effect on the data. A GET request retrieves data by specifying the parameters in the URL portion of the request. The length of the URL remains limited in the GET method. It is used when data does not require security as in the GET method the parameters passed are visible in the URL.
Requests Header for URI:

  • POST: The POST method is used to send or upload a file to a server. It is also used in HTML form submission. The parameters passed in POST are sent via headers instead of passing it in the URL thus the parameters are not visible in the URL. Furthermore, the method is not efficient because the method is non-idempotent (idempotence is a property that is applied multiple times to give the same result). 

Difference between GET and POST methods:

Used to receive data or information using URL. Used to send or upload data on the server using URL.
Parameters passed are visible in the URL. Parameters are not visible as they are part of headers.
GET request is often cacheable. POST requests can hardly be cacheable.
More efficient due to idempotence property. Less efficient due to non-idempotence.
Helps to send non-sensitive data. Helps to send sensitive data.

  • HEAD: HEAD is similar to GET but it is used to obtain the information regarding the document, not the document itself i.e. its aim is to get the metadata in response like filetype, the Content-Length, the Content-Encoding, and other header parameters.
Requests Header for URL:

Response Header for the Request

  • PUT: Replaces all current representations of the target resource with the uploaded content.
  • DELETE: Removes all current representations of the target resource given by a URI. The Server will DELETE the file that was passed in the request method.
  • CONNECT: Establishes a tunnel to the server identified by the URL passed.
  • OPTIONS: This method helps us to know about all the methods that we can use or have permission to perform on a particular URL.
  • TRACE: This method is used to echo the contents of an HTTP request back to the requester which can be used for debugging purposes at the time of development.

We hope this helps. If any suggestions or doubts you can add a comment and we will reply as soon as possible.

No comments:

Post a Comment