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:
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 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.
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:
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.
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.
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.
Upon successful creation of a new resource, the origin server is required to inform the user agent through a 201 (Created) response.
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.
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.
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.
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.
The best articles, links, and news delivered once a week to your inbox.