在 REST 中,我应该返回表示以响应 PUT 吗? [英] In REST, should I return the representation in response to a PUT?

查看:37
本文介绍了在 REST 中,我应该返回表示以响应 PUT 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以想象,另一个客户端在此期间也修改了资源的其他方面.那么,尽管存在带宽开销,但始终在对 PUT 的响应中包含完整表示是最佳实践吗?

It is conceivable that another client also modified other aspects of the resource in the interim. So is it best practice to always include the full representation in the response to a PUT, despite the bandwidth overhead?

推荐答案

Jldupont 的评论为我指明了正确的方向.我将使用 ETags 来确定资源是否已被修改,通过使用 If-match 标头执行条件 PUT,如此处所述.

Jldupont's comment pointed me in the right direction. I will use ETags to determine whether the resource has been modified, by doing a conditional PUT using the If-match header, as described here.

然后,如果发生冲突,我会让用户决定是从服务器获取最新的表示 (GET) 还是用他自己的覆盖更改.

Then, in case of a conflict, I'll let the user decide whether to fetch the latest representation from the server (GET) or overwrite the changes with his own.

因此,没有必要在对 PUT 的响应中返回完整的表示来帮助检测和解决冲突.

Thus, there is no need to return the full representation in the response to the PUT just to help with conflict detection and resolution.

这篇关于在 REST 中,我应该返回表示以响应 PUT 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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