应该RESTful'PATCH'操作return什么的?
Should RESTful 'PATCH' operation return something?
我正在纠结什么是 PATCH 方法的最佳实践。
我看到了几种可能性:
- Return HTTP 状态代码
200 OK
已更新对象。
- Return HTTP 状态代码
204 No Content
.
哪个最好?
specification 状态:
The 204 response code is used because the response does not carry a
message body (which a response with the 200 code would have). Note
that other success codes could be used as well.
这只是意味着您可以决定 return 或 body,然后响应代码应分别为 200
或 204
。没有一个比另一个更好或更坏。您可能会发现只 return 更改的内容是实用的,因此客户端不必发出新的请求来获取新的内容。
注意:使用 PATCH
非常棘手,因为您必须定义 mime-type
才能将 change-sets 应用到您的资源。这可能不是你想要的。通常情况下,PATCH
可以通过创建一个本来应该是资源的新资源来解决。
我正在纠结什么是 PATCH 方法的最佳实践。
我看到了几种可能性:
- Return HTTP 状态代码
200 OK
已更新对象。 - Return HTTP 状态代码
204 No Content
.
哪个最好?
specification 状态:
The 204 response code is used because the response does not carry a message body (which a response with the 200 code would have). Note that other success codes could be used as well.
这只是意味着您可以决定 return 或 body,然后响应代码应分别为 200
或 204
。没有一个比另一个更好或更坏。您可能会发现只 return 更改的内容是实用的,因此客户端不必发出新的请求来获取新的内容。
注意:使用 PATCH
非常棘手,因为您必须定义 mime-type
才能将 change-sets 应用到您的资源。这可能不是你想要的。通常情况下,PATCH
可以通过创建一个本来应该是资源的新资源来解决。