REST 的 HTTP MODIFY 动词?

发布于 2024-08-10 03:22:18 字数 899 浏览 5 评论 0 原文

据我所知,没有 RESTful 方法可以对资源应用修改。为此,您必须将资源作为一个整体进行 PUT,覆盖之前的表示。我认为这是问题的根源,特别是当资源具有很大的代表性时。

我相信这暗示了 HTTP1.1 中缺少动词:类似 MODIFY 或 PATCH 之类的东西。甚至 WebDAV 也没有这个动词(它有 PROPPATCH,其概念类似,但不是针对资源)。

当前的 HTTP 1.1 动词集对于现实世界的 RESTing 来说是否过于有限?

编辑:我在 IETF 找到了一项关于 PATCH 动词的提案

https://datatracker.ietf.org/doc/html/draft-dusseault-http-patch-15

该规范定义了新的 HTTP/1.1 [RFC2616] 方法 PATCH 用于应用部分 对资源的修改。

需要一种新方法 提高互操作性并防止 错误。 PUT 方法已经 定义为覆盖资源 拥有一个全新的身体,并且不能 可以重复使用来进行部分更改。 否则,代理和缓存,甚至 客户端和服务器可能会得到 对结果感到困惑 手术。 PATCH 被提到于 早期的 HTTP 规范,但不是 完全定义。

据我所知,这种动词的唯一问题是缺乏幂等性。

编辑:截至 2010 年 3 月,RFC 5789 已存在(HTTP 的 PATCH 方法)。

As far as I see, there's no RESTful way to apply a modification to a resource. In order to do it, you have to PUT the resource as a whole, overwriting the previous representation. I think this is source of problems, in particular when the resource has a large representation.

I believe this hints at the lack of a verb in HTTP1.1 : something like MODIFY, or PATCH. Not even WebDAV has this verb (it has PROPPATCH, whose concept is similar, but not for the resources).

Isn't the current HTTP 1.1 set of verbs too limited for real world RESTing ?

Edit: I found a proposal at IETF about the PATCH verb

https://datatracker.ietf.org/doc/html/draft-dusseault-http-patch-15

This specification defines the new
HTTP/1.1 [RFC2616] method PATCH
that 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 can not
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. PATCH was mentioned in
earlier HTTP specifications, but not
completely defined.

As far as I see, the only problem of such a verb is lack of idempotency.

Edit: As of March 2010, RFC 5789 exists (PATCH Method for HTTP).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半世蒼涼 2024-08-17 03:22:19

您可以将资源划分为可单独更新的子资源。

例如,您有一个代表用户帐户信息的 /user 资源,您可以创建一个 /user/email 子资源,然后对其执行 PUT 以仅更新电子邮件。

You could partition the resource into individually updatable sub-resources.

E.g. you have a /user resource representing user account information you could create a /user/email sub-resource, then do a PUT on it to update just the email.

寻找我们的幸福 2024-08-17 03:22:19

您可以使用 POST 进行部分更新。这并不理想,但相当安静。

You can use POST for partial updates. It's not ideal, but it's fairly RESTful.

转瞬即逝 2024-08-17 03:22:19

有充分的理由没有这样的动词来做到这一点。这几乎是不可能管理的。想象一下数百个客户端以这种方式修改相同的资源,您如何知道您的修改最终在哪里?如果顺序很重要,并且您的“补丁”实际上是在另一个“补丁”之后添加的,而现在您要添加的内容实际上不是添加的内容,该怎么办?将 PUT 与 ETag 标头一起使用是一种更明智的修改资源的方法,而不是尝试将一些具有未知结果的新动词拼凑在一起。为了获得可重复的结果,必须实际获取资源只是一个很小的代价。

There is good reason there is no such verb to do this. It's almost impossible to manage. Think of 100's of clients modifying the same resource in this way, how do you know where your modification ends up? What if order matters, and your "patch" is actually added after another "patch" and now what you meant to add i actually not what was added. Using PUT with ETag headers is a much more sane approach to modifying a resource then trying to hobble together some new verb with unknown results. Having to actually GET the resource is a small price to pay for repeatable results.

迷途知返 2024-08-17 03:22:19

我希望有标准化且受支持的动词,例如...

  • FIND、SEARCH 或 QUERY - 因此很明显,请求不是针对某个资源,而是针对其他资源的位置。也许用处有限。
  • 移动、复制、链接——非常方便,它们的作用类似于命令行工具。
  • DISCOVER、MAP、INDEX 或 SITEMAP - 这样您就可以获得资源布局,其概念类似于 wsdl 文件或 xmlrpc 的 system.listMethods。
  • BEGIN、ACQUIRE 或 LOCK,以及 COMMIT、END、DONE 或 RELEASE - 清楚地表明您何时开始和结束事务或使用中间资源。
  • 修改、更新、修补 - 因为我们都想要它

I wish there were standardized and supported verbs like...

  • FIND, SEARCH, or QUERY - so its clear the request is not for a resource, but the locations of other resources. Maybe only limited usefulness.
  • MOVE, COPY, LINK - just damn handy, they'd act similar to the command line tools.
  • DISCOVER, MAP, INDEX, or SITEMAP - so you can get a layout of resources, similar in concept to a wsdl file, or xmlrpc's system.listMethods.
  • BEGIN, ACQUIRE, or LOCK, and COMMIT, END, DONE, or RELEASE - to make it clear when you're starting and ending transactions, or using intermediate resources.
  • MODIFY, UPDATE, PATCH - because we all want it
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文