HTTP methods and http methods

Source: Internet
Author: User

HTTP methods and http methods

I. Basics

The so-called HTTP request method is to tell the server in advance what type of operations you want to perform, as if you order food before eating, tell the restaurant to prepare for you what kind of food.

 

There are a total of 8 types of methods

 

GET

HEAD

POST

PUT

DELETE

OPTIONS

TRACE

Extension Method

 

  1. GET

As the name implies, a child asks his mother for candy and reaches out to ask the server for something. The server returns the resource if this resource exists and permits it. Otherwise, it returns other resources. For example, if this resource does NOT exist, it is 404 not found.

 

  1. HEAD

The header of an http packet is called the header information. Similar to the GET method, the http packet also asks the server for resources, but unlike GET, in the response, http only returns the object's header information, instead of completely returning the entity's body.

 

Therefore, this is like the Sentinel of the army before the war.

HEAD is usually used for probing, and HEAD --

  • You can quickly learn about resources without obtaining resources, such as their types and file sizes,
  • You can also use the response code to check whether the resource exists,
  • You can also check whether the resource has been modified.

 

  1. PUT

In contrast to GET, you have to pay before you GET. The PUT method is used to submit, upload, and write modifications to the server.

 

  1. POST

POST is used to provide form data to the server.

 

  1. DELETE

Is to delete, request the server to delete the resource specified in the request URL.

 

  1. OPTIONS

Therefore, this method is the method that the request server notifies the client of its support. The following HTTP provides developers with the right to extend the method. In addition, not every method server supports the implementation of these seven methods, depending on the server developer.

For example, before ordering food, we need to ask the restaurant for a meal order to see what dishes it provides.

Generally, the server returns the supported methods.

 

  1. TRACE

TRACE indicates tracing.

When we order a meal, we may verbally tell the waiter, and then the waiter tells the chef that the transmitted information may be modified due to errors in the delivery process.

 

Similarly, when a client initiates a request to the server, the request may need to pass through the firewall, proxy, gateway, and other intermediate nodes to reach the server. These intermediate nodes have the right to modify the original HTTP request, therefore, HTTP allows the client to initiate such a request, so that the server returns a request that eventually reaches the server to the client, so that the client can know whether its original request has been modified and where it has been modified.

 

 

 

(8) Extension Method

Because the above seven methods have already met the basic requirements, but there are still special circumstances that cannot be met. Therefore, the extension method is not defined in the HTTP1.1 specification. Therefore, HTTP allows developers to customize some municipal implementation methods. For example, LOCK, MOVE, COPY, and so on.

 

Ii. Additional articles-AboutPUTAndPOSTDifference

In the official HTTP Definition

ThePOSTMethod is used to request thatthe origin server accept the entity enclosed in the request as a newsubordinate of the resource identified by the Request-URI in the Request-Line

 

The POST method is used in a request. The origin server uses the entity content in the request as the subordinate resource of the resource specified by the request URI in the request line.

ThePUTMethod requests that the enclosedentity be stored under the supplied Request-URI. if the Request-URI refers to an already existing resource, the enclosedentity shocould be considered as a modified version of the one residing on theorigin server. if the Request-URI does not point to an existing resource, and that URI iscapable of being defined as a new resource by the requesting user agent, theorigin server can create the resource with that URI."

The PUT method requires that the encapsulated object is stored in the specified place of the request URI.

If the requested URI points to an existing resource, the encapsulated entity should be considered as the modified version of the entity residing on the original server.

 

The discussion on stackOverFlow tends to be like this:

PUT is idempotent. The so-called idempotence is whether repeated operations will result in the same result. For example, x = 5 is idempotent, it doesn't matter how many times you execute it. The results are the same, but x ++ is not. The results of each execution are different. PUT is idempotent.

 

PUTImplies putting a resource-completely replacing whatever is available at the given URL with a differentthing. by definition, a PUT is idempotent. do it as always times as you like, andthe result is the same. x = 5 isidempotent. you can PUT a resource whether it previusly exists, or not (eg, toCreate, or to Update )!

POSTUpdates a resource, adds asubsidiary resource, or causes a change. a post is not idempotent, in the waythat x ++ is not idempotent.

Note: The Source is http://stackoverflow.com/questions/630453/put-vs-post-in-rest

 

Personal Understanding: both PUT and POST can be used to create and modify resources on the server, but how to choose to use them depends on whether repeated requests will produce different results when using POST, if yes, you must use PUT. If not, there is no relationship between PUT and POST.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.