Http PUT 进行增量更新

发布于 2024-12-09 23:35:57 字数 738 浏览 0 评论 0原文

我们已经实现了 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 技术交流群。

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

发布评论

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

评论(3

乱世争霸 2024-12-16 23:35:57

您将被反复告知您不应执行部分 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

静水深流 2024-12-16 23:35:57

如果您的客户支持它,我认为 PATCH 就是您正在寻找的:

PATCH以可预测且有效的事务方式覆盖指定资源的一部分(如果无法执行整个补丁,则服务器不应执行其中的任何部分)

If your client supports it, I think PATCH is what you are looking for:

PATCH to override a portion of a specified resource in a predictable and effectively transactional way (if the entire patch cannot be performed, the server should not do any part of it)

孤千羽 2024-12-16 23:35:57

虽然不是很流行,但 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文