I have a REST API that allows modification of resources using HTTP POST. It's possible that a client may submit a POST request that results in no modification of the resource. I'm thinking about using the 304 response generally used for conditional responses to indicate that the request had no effect. I haven't been able to find any examples of this being done, so I figured I'd ask here and see if anyone else is doing this or has an opinion about it.
相关问题
- Angular RxJS mergeMap types
- Design RESTful service with multiple ids
- HTML form is not sending $_POST values
- Axios OPTIONS instead of POST Request. Express Res
- Plain (non-HTML) error pages in REST api
相关文章
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- 请大神帮忙 post向https接口发送数据 部署到服务器为什么运行一会后就会报空指针
- WCF发布Windows服务 POST方式报错 GET方式没有问题 应该怎么解决?
- 用 $.ajax POST 请求数据报错
- 设备发送一个http post请求,接收不到
- Is a unicode user agent legal inside an HTTP heade
- Show a different value from an input that what wil
- Got ActiveRecord::AssociationTypeMismatch on model
After some consideration, I've decided to stick to a normal 200 response with the unchanged resource entity. My initial intent was to provide a concise way to indicate to the client that the resource was not modified. As I thought more about it I realized that in order to do anything useful with the 304 response, they would have to already have a cached version and in that case it would be trivial to compare the version of the cached copy with the version returned in a 200 response.
HTTP POST in the RESTful approach implies a creation of a resource, not a modification. For modification you should use HTTP PUT.
Solution of your problem is HTTP Status 200 OK when something was modified and HTTP Status 204 No Content when there was no modification. According to:
For example: