使用HTTP 304响应POST [英] Using HTTP 304 in response to POST

查看:155
本文介绍了使用HTTP 304响应POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个REST API,允许使用HTTP POST修改资源。客户端可能会提交POST请求,导致不修改资源。我正在考虑使用通常用于条件响应的304响应来表明请求没有效果。我还没有找到任何这方面的例子,所以我想我会问这里,看看是否有其他人这样做或对此有意见。

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.

推荐答案

经过一番考虑后,我决定坚持使用未更改的资源实体进行正常的200响应。我最初的意图是提供一种简明的方法来向客户表明资源未被修改。当我更多地考虑它时,我意识到为了对304响应做任何有用的事情,它们必须已经有一个缓存版本,在这种情况下,将缓存副本的版本与返回的版本进行比较是微不足道的。 200响应。

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 304响应POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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