RESTful 'PUT' 操作会返回一些东西吗? [英] Does a RESTful 'PUT' operation return something?

查看:23
本文介绍了RESTful 'PUT' 操作会返回一些东西吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在响应正文中不返回任何内容(空值)的 RESTful PUT 操作是否符合 REST 事务的相关规范.

I was wondering whether a RESTful PUT operation that returns nothing (null) in the response body complies with relevant specifications for REST transactions.

推荐答案

HTTP 规范 (RFC 2616) 有许多适用的建议.这是我的解释:

The HTTP specification (RFC 2616) has a number of recommendations that are applicable. Here is my interpretation:

  • HTTP 状态代码 200 OK 用于成功 PUT 更新到现有资源.不需要响应机构.(根据 第 9.6 节204 无内容 更合适.)
  • HTTP 状态代码 201 Created 用于新的成功 PUT资源,在 Location 标头字段中返回新资源的最具体 URI,以及在响应正文中回显的资源的任何其他相关 URI 和元数据.(RFC 2616 第 10.2.2 节)
  • HTTP 状态代码 409 Conflict 由于 PUT 不成功到第 3rd 方修改,包含差异列表尝试更新和响应中的当前资源之间身体.(RFC 2616 第 10.4.10 节)
  • HTTP 状态代码 400 Bad Request 表示失败PUT,在响应正文中带有自然语言文本(如英语)这解释了为什么 PUT 失败.(RFC 2616 第 10.4 节)
  • HTTP status code 200 OK for a successful PUT of an update to an existing resource. No response body needed. (Per Section 9.6, 204 No Content is even more appropriate.)
  • HTTP status code 201 Created for a successful PUT of a new resource, with the most specific URI for the new resource returned in the Location header field and any other relevant URIs and metadata of the resource echoed in the response body. (RFC 2616 Section 10.2.2)
  • HTTP status code 409 Conflict for a PUT that is unsuccessful due to a 3rd-party modification, with a list of differences between the attempted update and the current resource in the response body. (RFC 2616 Section 10.4.10)
  • HTTP status code 400 Bad Request for an unsuccessful PUT, with natural-language text (such as English) in the response body that explains why the PUT failed. (RFC 2616 Section 10.4)

这篇关于RESTful 'PUT' 操作会返回一些东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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