PUT 请求主体是否必须包含整个实体?
在资源上定义 PUT 方法时,是否需要/标准/惯例包含资源的整个定义(即创建资源所需的所有内容),还是仅发送更新的字段也可以接受?
例如,如果我有一个具有 10 个属性(其中一个称为数量)的资源,并且我想将该数量更新为指定值。仅 PUT 数量可以接受吗?
那么其他9个属性呢?假设每个属性都可以单独更新,那么简单地定义请求正文以将所有 10 个属性设为可选是否是一种好的做法?
When defining a PUT method on a resource is it required/standard/customary to include the entire definition of the resource (i.e. everything needed to create it) or is it also acceptable to send only updated fields?
For example, if I have a resource with 10 attributes including one called quantity and I want to update the quantity to a specified value. Is it acceptable to PUT only the quantity?
What about the other 9 attributes? Assuming each attribute could be updated individually, is it good practice to define the request body simply to have all 10 attributes as optional?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RESTful 使用时的 PUT 旨在替换整个资源,因此您需要包含完整的属性集。
也就是说,无论如何,REST 在大多数情况下使用得相当不正确,只要您的 API 记录良好,您就可以执行您认为最适合您情况的任何操作。
PUT when used RESTfully is intended to replace the entire resource, so you would want to include the full set of attributes.
That said, REST is used rather improperly in most cases anyway, and as long as your API is documented well, you can do whatever you deem most appropriate for your situation.