Skip to content
Related Articles

Related Articles

Improve Article

Explain Request Verbs

  • Last Updated : 24 Sep, 2021

HTTP methods provide a way to specify the desired action to be performed on the given resource. The result depends upon the implementation of the server and it can be pre-existing data or data that is dynamically generated.

The HTTP methods that are most commonly used are GET, POST, PUT, PATCH, and DELETE which correspond to CRUD (create, read, update, delete) operations.

Request methods:

  1. GET: The GET method is used to retrieve information identified by Request-URL. It is the primary mode of information retrieval. It doesn’t change the state of the requested resource and is said to be a safe method. If the Request URL refers to a data-producing process, the produced data will be returned in response instead of the source text, unless the text is the output of a process.
     
  2. POST: The POST method is used to send data to the server as a request body. This method indicates that the data in the body of the request is intended to be accepted and most likely to be stored in the server. The Content-Type header indicates the type of the body of the request. It is mostly used while uploading a file or while submitting a complete web form. Responses to the method will not be cacheable until the response contains appropriate Cache-Control or Expires header fields.
     
  3. PUT: The PUT method is used to replace the already existing state of the resource or create the resource if the resource doesn’t exist (decided by the origin server) with the request payload.
     
  4. PATCH: The PATCH method is used to make a partial update to a resource. It can be considered as an instruction set that describes the modification of data already present on the server to produce a new version of the data and it is not considered as the complete resource.
     
  5. DELETE: The DELETE method is used to delete a specified resource on the origin server. The client cannot be assured that the operation was performed, even though the status code which is returned from the server indicates it.
     
  6. HEAD: The HEAD is identical to the GET request but the server must not send the response body but should send the same headers as it would have sent if URI was requested with the GET method. It can be used to get metadata without transferring the response body from the server and is often used for testing hypertext links for validity, accessibility, and recent modification.
     
  7. CONNECT: The CONNECT method is used to establish an end-to-end HTTP tunnel through a proxy server.
     
  8. OPTIONS: The OPTIONS method requests allowed communication options for a given resource. This request can be sent to find out the supported HTTP methods and other options that are supported without requesting the resource.
     
  9. TRACE: The TRACE method requests the server to send the exact request, as received by it, in the response body. It is useful for diagnostic purposes.

A simple GET request in javascript:

Javascript






// GET request
  
    // Convert reponse to json
      .then((response) => response.json())
      
    // Print data to console
      .then((data) => console.log(data));


Response

Important terminologies:

  • Safe: An HTTP method is safe if it doesn’t change the state of the server. In other words, a method is safe if it can be used only for reading or retrieval of the data. Several HTTP methods are safe, for example, GET and HEAD. All safe methods are idempotent, but the converse is not true. For instance, the PUT and DELETE, both the methods are idempotent but are unsafe.
     
  • Idempotent: An HTTP method is idempotent if the operation produces the same result when executed once or multiple times while leaving the server in the same state. In other words, an idempotent method should not cause any unintended effect regardless of the number of times it is executed. The GET, HEAD, PUT, and DELETE methods are idempotent if they are implemented correctly. All safe methods are also idempotent.
     
  • Cacheable: A cacheable response is an HTTP response that can be cached, which is stored in order to access for later use, saving the new request to the server. This avoids unnecessary requests to the server.

Request method

Request has payload

Response has payload

Safe

Idempotent

Cacheable

GET

Optional

 Yes

Yes

Yes 

Yes

POST



Yes

Yes

No

No

Yes

PUT

Yes

Yes

No

Yes

No

PATCH

Yes

Yes

No

No

No

DELETE

Optional

Yes



No

Yes

No

HEAD

Optional

No

Yes

Yes

Yes

CONNECT

Optional

Yes

No

No

No

OPTIONS

Optional

Yes

Yes

Yes



No

TRACE

No

Yes

Yes

Yes

No




My Personal Notes arrow_drop_up
Recommended Articles
Page :