Sign in
Log inSign up

What are the different type of Http requests ?

Kratika Tiwari's photo
Kratika Tiwari
·Aug 13, 2021·

5 min read

What is HTTP?

Http stands for Hypertext Transfer Protocol. It is a protocol which allows fetching of resources from Web. It is the foundation of any data exchange on the Web and it is a client-server protocol, which means requests are initiated by the recipient, usually the Web browser.

What are HTTP Requests?

In a web browser, the communication takes place in the form or request/ response cycles. The user sends a request to the Web and according to the request sent, the browser fetches the required information and returns the response to the user.
There are various HTTP requests methods each one for a specific purpose. These request methods are case sensitive and hence are always written in upper case.

How do Http Requests work?

HTTP requests are basically an intermediate between client and server. What actually happens is that a client sends a request (HTTP request) to the server, and the server processes that request and returns a back a response about the asked request. So in this way as we can notice, an HTTP request helps in communication between client and server.

What are different Http Request methods?

Different Http Requests are :

  • GET
  • POST
  • PUT
  • HEAD
  • OPTIONS
  • PATCH
  • DELETE

1. GET

Many of us might have used GET request while working with forms. So what actually a GET request is? Basically, a GET request requests the data from a specific resource to which the GET request is sent. GET request is not secure as all the data sent is exposed in URL bar , therefore GET request should not be used to send secure data. GET request is only used for retrieving data and not modifying any resources. GET requests also have length restrictions. When we make two GET requests one after another, the second request will not be considered unless the first request is delivered. So this is how a GET request works.

2. POST

POST requests are used to send data to server and then to create or update a resource. It is often used when uploading a file or when submitting a completed web form. In GET request, the data cannot be modified , but in POST request the data can be modified and updated. POST requests are never cached and they do not have any length restrictions. In POST request, the parameters are not stored in browser history. POST request can be used to send secure data as the data is not exposed into URL bar.

3.PUT

PUT requests are used to send the data to the server to create/update a resource. The action performed by the POST method might not result in a resource that can be identified by a url. PUT request is idempotent, i.e. if we call a PUT request once or several times, it will always return the same response whereas POST request may have additional effects. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.

4.HEAD

HEAD method is similar to GET method except that GET returns with a body text whereas HEAD returns only with the header and not the body. So basically HEAD method can be used to check the data before sending a GET request in case of large amount of data. In case of a large file, we can send a HEAD request and check the data. If the response to a HEAD request shows that a cached URL response is now outdated, the cached copy is invalidated even if no GET request was made.

5.OPTIONS

OPTIONS method is used to describe communication options for a resource. When we send an OPTIONS request, it returns all the available communication methods for that particular resource. It returns all the supported HTTP methods and other options supported for the target resource before sending the actual request. Before even sending a request, the client can make requirements according to the method request he wants to send. A client can specify a URL with this method, or an asterisk (*) to refer to the entire server. The HTTP OPTIONS method is both secure and idempotent and is only intended to provide information on how to interact with a resource. It cannot modify a resource.

6.PATCH

PUT method replaces a resource completely while PATCH method is used to modify and update a resource partially. The PATCH method may change the server state. We can send data to the server in the body of an HTTP PATCH message. The type and size of data are not limited. But we need to specify the data type in the Content-Type header and the data size in the Content-Length header. The PATCH method is not idempotent. In PATCH method we just need to send the modified fields we want to update and not all the fields. So for large amount of data where we want to make changes, it can reduce the amount of data to be sent and hence will take less time in processing.

7.DELETE

DELETE method is used to delete a resource from the server. The delete request may also change the server state. DELETE method is also idempotent which means if we call a DELTETE request multiple times, it will not additionally affect the state. DELETE method requires an id of the resource we want to delete to perform the delete operation. Sending a message body on a DELETE request might cause some servers to reject the request. A successful response MUST be 200 (OK) if the server response includes a message body, 202 (Accepted) if the DELETE action has not yet been performed, or 204 (No content) if the DELETE action has been completed but the response does not have a message body.

So this was all about Http requests.