Parse the six request methods of the HTTP protocol, what is the difference between get, head, put, delete, post

The standard Http protocol supports six request methods, namely:

1、GET

2、POST

3、PUT

4、Delete

5、HEAD

6、Options

       But in fact, we only use GET and POST in most cases. If you want to design a web application that conforms to the RESTful specification, all six methods are used. But even if you don't want to get into REST for a while, it's still useful to understand the nature of these six methods. You will find that the original web is also very concise and clear. The six methods are described in turn below.

      1, GET: GET can be said to be the most common, and its essence is to send a request to obtain a resource on the server . The resource is returned to the client through a set of HTTP headers and presentation data (such as HTML text, or images or videos, etc.). In a GET request, rendering data is never included.

       2, HEAD: HEAD and GET are essentially the same, the difference is that HEAD does not contain presentation data, but only HTTP header information. Some people may think that this method is useless, but it is not the case. Imagine a business scenario: to determine whether a resource exists, we usually use GET, but HEAD is more meaningful here.

       3, PUT: This method is relatively rare. HTML forms don't support this either. In essence, PUT and POST are very similar in that they both send data to the server, but there is an important difference between them. PUT usually specifies the storage location of resources, while POST does not. The data storage location of POST is determined by the server itself.

       For example: such as a URL for submitting blog posts, /addBlog. If PUT is used, the submitted URL will be like this "/addBlog/abc123", where abc123 is the address of this blog post. If POST is used, the address will be notified to the client by the server after submission. Most blogs are like this these days. Obviously, PUT and POST are not the same. Which one to use depends on the current business scenario.

      4, DELETE: delete a resource. Basically, this is also rare, but there are still some places such as Amazon's S3 cloud service that uses this method to delete resources.

     5, POST: Submit data to the server. This method is widely used, and almost all submission operations currently rely on this to complete.

      6, OPTIONS: This method is very interesting, but rarely used. It is used to get the methods supported by the current URL. If the request is successful, it will include a header named "Allow" in the HTTP header with the value of a supported method, such as "GET, POST".

In fact, there is also a TRACE method, but this is basically not used, so I won't introduce it here.

       The above six methods, we can correspond to the database CRUD addition, deletion, modification and query operations: 

CREATE :PUT 

READ:GET 

UPDATE:POST 

DELETE:DELETE 

In this way, the perfect unification of HTTP and database operations (in fact, not only databases, but any data such as file charts) is achieved, which is also one of the essence of REST

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324805681&siteId=291194637