The difference between put and post usage in the HTTP protocol

Source: Internet
Author: User

Note: This article turns from http://blog.csdn.net/mad1989/article/details/7918267

It is argued that you should use post to create a resource, use a put to update a resource, and some argue that you should use put to create a resource, use post to update a resource, and the idea that you can create or update a resource 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 distinction.
    Methods can also has the property of ' Idempotence ' in that (aside from error or Expira tion issues) The side-effects of N > 0 Identical requests is the same as for a single request.
   

      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}, very simple, replace {blog-name} with our blog name, send an HTTP put or POST request to this URI, the body part of HTTP is the blog post, this 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.

The difference between put and post usage in the HTTP protocol

Related Article

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.