REST中成功的DELETE语句的HTTP状态返回码是什么? [英] What is the HTTP status return code for a successful DELETE statement in REST?

查看:1995
本文介绍了REST中成功的DELETE语句的HTTP状态返回码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Spring如何处理REST Web服务(但我不知道它是否是Spring相关的答案,或者更一般地说它只与REST概念相关)。

I am studying how to Spring handle REST web services (but I don't know if it is a Spring related answer or more generically it is related only to REST concept).

所以我的疑问是:成功的DELETE语句的HTTP状态返回代码究竟是什么?

So my doubt is: what exactly is the HTTP status return code for a successful DELETE statement?

204 还是 200

我知道 200 表示我的请求已正确完成但在线阅读似乎我希望它在成功获得GET返回内容之后 而不是在删除之后。

I know that the 200 means that my request was correctly fulfilled but reading online it seems to me that it I expect it after a successful GET returning content and not after a delete.

某处我发现 204
成功PUT或DELETE后获得 。这是真的吗?我无法理解,这意味着响应是空的,为什么空响应意味着PUT或DELETE操作已经成功了?

Somewhere I found that the 204 status is obtained after successful PUT or DELETE. Is it true? I can't understand, it means that the response is empty, why an empty respons means that the PUT or the DELETE operation are gone succesfull?

推荐答案

对于每种方法,哪种HTTP状态代码是正确的,没有严格的规则。这取决于究竟发生了什么,需要向客户发送什么信息等等。我可以想到几个例子:

There are no strict rules on which HTTP status code is the correct one for each method. It depends on what exactly happened, what information you need to send to the client, etc. I can think of a few examples:


  • 成功的 DELETE ,没有进一步的信息。 204无内容

  • A successful DELETE, with no further information. 204 No Content

成功 DELETE ,但您有关于应该删除的相关孤立资源的警告。 200 OK

A successful DELETE, but you have a warning about related orphan resources that should be deleted too. 200 OK.

您已接受 DELETE 请求,但可能需要很长时间,而且您将异步执行此操作。客户应该稍后检查。 202接受

You accepted the DELETE request, but it might take a long time and you're going to do it asynchronously. The client should check it later. 202 Accepted.

您已接受 DELETE 请求,但无法删除资源,而是将URI重置为默认值。 205重置内容

You accepted the DELETE request, but the resource can't be removed and the URI is instead reset to a default. 205 Reset Content.

这篇关于REST中成功的DELETE语句的HTTP状态返回码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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