下面这四个就不需要解释了:
POST = 新增
GET = 读取
PUT = 更新
DELETE = 刪除
POST or PUT?
PUT puts a file or resource at a specific URI, and exactly at that URI. If there’s already a file or resource at that URI, PUT replaces that file or resource. If there is no file or resource there, PUT creates one. PUT is idempotent, but paradoxically PUT responses are not cacheable.
POST sends data to a specific URI and expects the resource at that URI to handle the request. The web server at this point can determine what to do with the data in the context of the specified resource. The POST method is not idempotent, however POST responses are cacheable so long as the server sets the appropriate Cache-Control and Expires headers.
应用:
POST:- Used when the client is sending information or data to the server—for example, filling out an online form (i.e. Sends a large amount of complex data to the Web Server).
PUT:- Used when the client is sending a replacement document or uploading a new document to the Web server under the request URL.
PUT or PATCH?
PUT replace the ENTIRE RESOURCE with the new representation provided (no mention of related resources in the spec from what i can see)
PATCH replace parts of the source resource with the values provided AND|OR other parts of the resource are updated that you havent provided (timestamps) AND|OR updating the resource effects other resources (relationships)
通俗讲,全部更新和局部更新。
put与patch比也不是一无是处: