Some hold that post should be used to create a resource, and put should be used to update a resource; some hold that put should be used to create a resource and post should be used to update a resource; another point is that you can use either put or post to create or update a resource. These ideas only show the style. In the debate, they only argue about which style is better. In fact, using put or post doesn't mean that it is the action of creating or updating resources. This is not a style issue, it is a semantic issue.
In HTTP, put is defined as the idempotent method, and post is not. This is an important difference.
"Methods can also have the property of" 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."
In the above words, if a method is repeatedly executed multiple times, the results will be the same, that is, idempotent.
For example, a blog system provides a web API in the http: // superblogging/blogs/post/{blog-name} mode, replace {blog-name} with our blog name and send an http put or POST request to this URI. The HTTP body is a blog, which is a simple example of rest API. Should we use the put method or the POST method? It depends on whether the behavior of this rest service is idempotent. If we send two http: // superblogging/blogs/post/sample requests, what kind of behavior is the server side? If two blog posts are generated, it indicates that this service is not idempotent, because multiple use operations have a side effect. If the next request overwrites the first one, the service is idempotent. In the previous case, the POST method should be used. In the latter case, the put method should be used.
Maybe you will think that the difference between the two methods is no big deal, and there will be no problems if you use the wrong method, but if your service is put on the Internet, if you do not follow the HTTP protocol specifications, it may cause troubles to you. For example, Google crawler may also access your service. If a service that is not indempotent can be accessed using the indempotent method, the status of your server may be modified by the crawler, this should not happen.