Http put and post differences

Source: Internet
Author: User

Reproduced:

The

has the view that a post should be used to create a resource, a put to update a resource, and some argue that a put should be used to create a resource, a post to update a resource, and a view that a resource can be created or updated with either a put or post. These views only see the style, arguing about which style is better, in fact, put or post, not to see whether it is to create or update the resources of the action, this is not the problem of style, but the question of semantics.



in HTTP, put is defined as a method of idempotent, and post is not, which is a very important difference.



    "Methods can also has the" idempotence "in that (aside from error or expiration issues) The side-effects of N > 0 Identical requests is the same as for a single request. "



above is to say that if a method is repeated several times, the effect is the same, it is idempotent.



      to cite a simple example, if there is a blog system that provides a web API, the pattern is Http://superblogging/blogs/post/{blog-name }, it's easy to replace {blog-name} with our blog name, send an HTTP put or POST request to this URI, and the body part of HTTP is the blog post, which is a very simple rest API example. Should we use the Put method or the Post method? Depending on whether the behavior of this rest service is idempotent, what is the server side behavior if we send two http://superblogging/blogs/post/Sample requests? If there are two blog posts, it means that the service is not idempotent, because the use of multiple uses has a side effect, if the latter request to overwrite the first request, then the service is idempotent. In the former case, the Post method should be used, and in the latter case, the put method should be used.



You may think that the difference between the two methods is not a big deal, the use of the wrong is not a problem, but your service is put on the Internet, if you do not comply with the HTTP protocol specifications, you can cause trouble. For example, maybe Google crawler will also visit your service, if you let a service that is not indempotent can be accessed by Indempotent method, then the status of your server may be crawler modified, this should not happen.

Http put and post differences

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.