我想知道人们对在响应体中不返回任何(null)的RESTful PUT操作有什么看法。
当前回答
“Created”的Http响应代码201以及指向客户端可以找到新创建资源的“Location”标头。
其他回答
“Created”的Http响应代码201以及指向客户端可以找到新创建资源的“Location”标头。
空的Request体符合GET请求的原始目的,空的响应体也符合PUT请求的原始目的。
看起来好…虽然我认为一个基本的指示成功/失败/时间张贴/#字节接收/等等。会更好。
编辑:我一直在考虑数据完整性和/或记录保存;元数据,如MD5散列或接收时间的时间戳,可能对大型数据文件有帮助。
HTTP规范(RFC 2616)有许多适用的建议。以下是我的解读:
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)
HTTP/1.1规范(第9.6节)讨论了适当的响应/错误代码。但是,它不处理响应内容。
你想要什么?一个简单的HTTP响应代码(200等)对我来说似乎是直接而明确的。
推荐文章
- 有没有REST api的命名规范指南?
- 什么是HTTP中的“406-不可接受的响应”?
- 哪些HTTP方法与哪些CRUD方法相匹配?
- RESTful服务中部分更新的最佳实践
- JAX-RS / Jersey如何自定义错误处理?
- 有没有办法在python中做HTTP PUT
- 如何POST表单数据与Spring RestTemplate?
- Restful API服务
- 在哪里放置和如何在基于servlet的应用程序读取配置资源文件?
- 在用nodejs和express创建的REST API中设置响应状态和JSON内容的正确方法
- 如何POST JSON数据与PHP卷曲?
- REST身份验证方案的安全性
- 如何在package.json中使用“main”参数?
- 跨REST微服务的事务?
- JSF资源库的用途是什么,应该如何使用它?