REST 的 HTTP MODIFY 动词? [英] HTTP MODIFY verb for REST?

查看:21
本文介绍了REST 的 HTTP MODIFY 动词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,没有 RESTful 方式可以对资源进行修改.为了做到这一点,您必须将资源作为一个整体,覆盖以前的表示.我认为这是问题的根源,尤其是当资源具有很大的代表性时.

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.

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

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).

当前的 HTTP 1.1 动词集对于现实世界的 REST 来说是不是太有限了?

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

编辑:我在 IETF 发现了一个关于 PATCH 动词的提案

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

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

本规范定义了新的HTTP/1.1 [RFC2616] 方法补丁用于应用部分修改资源.

This specification defines the new HTTP/1.1 [RFC2616] method PATCH that is used to apply partial modifications to a resource.

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

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.

截至 2010 年 3 月,存在 RFC 5789(PATCHHTTP 方法).

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

推荐答案

没有这样的动词来做这件事是有充分理由的.管理几乎是不可能的.想想 100 多个客户以这种方式修改同一个资源,你怎么知道你的修改最终在哪里?如果顺序很重要,并且您的补丁"实际上是在另一个补丁"之后添加的,现在您要添加的内容实际上不是添加的内容.将 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.

这篇关于REST 的 HTTP MODIFY 动词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆