HTTP method中, PUT和PATCH两者有何区别, 大致如何用 ?

2017/1/8

描述

在我的意识中, 一直是这样的:

  1. PUT 对应 Update 操作

  2. PATCH 没有用过

但是今天看到这句话

PUT: 替换某个已有的资源。PUT操作虽然有副作用,但其应该是幂等的。

PATCH(RFC5789): 修改某个已有的资源。

遂有不解.

问题如下:

  1. 根据上面两句话, 都对应的 Update, 两者是 Update 的某种细粒度操作吗

  2. 接1, 详细阐述它们的区别 ?

上下文环境

  1. HTTP 1.1

  2. PUT PATCH

阅读 6.7k
1 个回答

PUT替换整个资源,PATCH修改资源的部分内容,粒度的不同。

This specification defines the new HTTP/1.1 [RFC2616] method, PATCH, which is used to apply partial modifications to a resource. A new method is necessary to improve interoperability and prevent errors. The PUT method is already defined to overwrite a resource with a complete new body, and cannot be reused to do partial changes. Otherwise, proxies and caches, and even clients and servers, may get confused as to the result of the operation. POST is already used but without broad interoperability (for one, there is no standard way to discover patch format support). PATCH was mentioned in earlier HTTP specifications, but not completely defined.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进