What are the HTTP Request Methods

July 20, 2023

An HTTP request is a communication sent from a client to a server with the purpose of requesting specific information or carrying out an action. HTTP serves as the protocol for data exchange on the internet.

Here we will discuss 5 most used HTTP request methods:

  • GET  - HTTP request method
  • HEAD - HTTP request method
  • POST  - HTTP request method
  • PUT - HTTP request method
  • DELETE - HTTP request method

 

GET - HTTP request method:

The GET method is used to fetch whatever information is associated with the Request-URI. If the Request-URI points to a data-producing process, the response will contain the produced data as an entity, not the actual source text of the process, unless the process's output happens to be that text.

 

HEAD - HTTP request method:

HEAD is comparable to GET, but it differs in that the server is not obligated to provide a response with a message-body. The meta-information that is found in the HTTP headers in response to a HEAD request must be equivalent to the information sent when responding to a GET request. This method allows obtaining meta-information about the entity referred to in the request without transferring the actual entity-body. HEAD is commonly used to validate the hypertext links and to check accessibility, and also to verify recent modifications.

 

POST - HTTP request method

The POST method is utilized to request that the origin server accepts. The enclosed entity within the request, establishing it as a new subordinate related to the resource identified by the Request-URI in the Request-Line. The key objectives of using the POST method encompass:

  1.  Adding annotations to pre-existing resources.
  2. Publishing messages on platforms like bulletin boards, newsgroups, mailing lists, or other article groupings.
  3. Transmitting a block of data, such as form submission results, to a data-handling process.
  4. Expanding a database through the execution of an append operation.

 

PUT - HTTP request method:

The PUT method is employed to make a request to the server, asking for acceptance of the enclosed entity data while associating it with the provided Request-URI. This versatile method serves two primary purposes: creating new resources and updating existing ones.

 

1. Updating Existing Resources:

When the Request-URI corresponds to an already existing resource, the enclosed entity is treated as an updated version of that resource, residing on the origin server.

 

2. Creating New Resources:

If the Request-URI does not point to an existing resource, the origin server has the freedom to create a new resource using the provided URI.

 

3. Successful Creation of a New Resource:

Upon successful creation of a new resource, the origin server is required to inform the user agent through a 201 (Created) response.

 

4. Successful Modification of an Existing Resource:

In cases where an existing resource is modified successfully, the server responds with either a 200 (OK) or 204 (No Content) status code to signify the successful completion of the request.

 

Handling Unrecognized Headers:

Furthermore, the recipient of the entity must not disregard any Content-* (e.g., Content-Range) headers that it encounters and does not understand or support. When such situations occur, a 501 (Not Implemented) response is returned, indicating that the server does not recognize or implement the specific headers involved.

 

Difference between the POST and PUT Requests:

The POST method is primarily used for submitting data to be processed to a specified resource. It is commonly used to create new resources on the server or trigger actions that do not necessarily result in creating a new resource.

On the other hand the PUT method is used to update or create a resource on the server at a specific URL. It is more focused on updating existing resources or creating new ones when the client knows the exact URL where the resource should be located.

 

DELETE - HTTP request method:

The DELETE method is employed to request the server to delete the resource identified by the Request-URI. While this method initiates the deletion process, it is possible for human intervention or other means on the origin server to override this operation.

As a result, the client cannot always be certain that the deletion has been executed. Nonetheless, the server should not indicate success unless, at the moment of the response, it genuinely intends to carry out the resource's deletion or relocate it to an inaccessible location.

Stay Tuned

The best articles, links, and news delivered once a week to your inbox.

DMCA.com Protection Status