HTTP PUT - 封闭的实体存储在提供的请求 URI 下,这是否意味着删除和添加?
根据规范:
PUT 方法请求将所包含的实体存储在 提供的请求 URI。如果 Request-URI 引用了一个已经存在的 资源,所包含的实体应该被视为修改过的 驻留在源服务器上的版本。
因此,如果我必须实现 RESTFul 服务来更改人员的年龄:
ID:100,姓名:John Doe,描述:高,年龄:40
至 60 岁,如果我的 PUT 请求包含
ID:100,姓名:John Doe,描述:高,年龄:60
或刚刚
年龄:60
服务器是否应该合并和更新更改的内容,或者完全删除并重新添加资源?
According to the spec:
The PUT method requests that the enclosed entity be stored under the
supplied Request-URI. If the Request-URI refers to an already existing
resource, the enclosed entity SHOULD be considered as a modified
version of the one residing on the origin server.
So if I have to implement a RESTFul service to change the age of a Person:
id: 100, name: John Doe, description: Tall, age: 40
to age 60, should my PUT request contain
id: 100, name: John Doe, description: Tall, age: 60
or just
age: 60
Should the server be expected to merge and update just what changed or completely delete and re-add the resource?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PUT 替换。如果您只想修改部分资源,请使用 PATCH(或为资源的各个方面分配单独的 URI)
PUT replaces. If you want to just modify part of the resource, use PATCH (or assign separate URIs to the individual aspects of the resource)