Http PUT 进行增量更新
我们已经实现了 RESTful Web 服务。 一个人看起来像
GET /person/1234
GET /person/list
POST /person
POST /person/list
PUT /person/1234
PUT /person/list
基本上,要创建一个人,您可以 POST 到 /person 或 /person/list
要更新一个人,您可以 PUT 到 /person/1234 或 /person/list
这样:
<person>
<id>1234</id>
<name>Name1</name>
<age>50</age>
<education>high school</education>
</person>
问题: 我可以使用 PUT 通过发送来更新某人吗
<person>
<age>55</age>
</person>
据我了解 PUT,您不能将其用于增量更新。我不应该使用 POST 来做到这一点吗?
我们能否放宽 PUT 对此用例的定义以使术语变得简单。 PUT 意味着更新,POST 意味着创建。
假设您无法要求客户端发送完整的资源表示以进行更新。
We've implemented a RESTful webservice. Here's how it looks like
GET /person/1234
GET /person/list
POST /person
POST /person/list
PUT /person/1234
PUT /person/list
Basically, to create a Person, you POST to /person or /person/list
To update a person, you PUT to /person/1234 or /person/list
A person looks like this:
<person>
<id>1234</id>
<name>Name1</name>
<age>50</age>
<education>high school</education>
</person>
Question:
Can I use PUT to update a person by sending
<person>
<age>55</age>
</person>
As I understand PUT, you cannot use it for incremental Updates. Shouldn't I use POST to do it?
Can we relax PUT's definition for this use-case to make the terminology simple. As then PUT will mean Update, POST will mean Create.
Assume that you cannot ask the client to send a complete resource representation for updates.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您将被反复告知您不应执行部分 PUT。规范说你不应该这样做。然而,我还没有听到令人信服的论据来说明这样做会产生哪些负面影响。
关于该主题的较长线程之一位于此处 http://tech.groups .yahoo.com/group/rest-discuss/message/17500
You will be told repeatedly that you should not do a partial PUT. The spec says you should not do it. However, I've yet to hear a convincing argument as to what are negative impacts of doing it.
One of the longer threads on the subject is here http://tech.groups.yahoo.com/group/rest-discuss/message/17500
如果您的客户支持它,我认为 PATCH 就是您正在寻找的:
If your client supports it, I think PATCH is what you are looking for:
虽然不是很流行,但 HTTP 中有一个 PATCH 动词。这就是它的意图,但不确定是谁实现的。 POST 通常用于修补,但据我所知,它不是 REST 标准,但如果您在环境中遵循该约定,则可以实现它。
Although not very popular, there is a PATCH verb in HTTP. This is what it is intended, but not sure who implements it. POST is usually used to patch, but it is not REST-standard, as far as I know, but you can implement it if you get that convention in your environment.