简体   繁体   English

REST中成功的DELETE语句的HTTP状态返回码是什么?

[英]What is the HTTP status return code for a successful DELETE statement in 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). 我正在研究如何Spring处理REST Web服务(但我不知道它是否是Spring相关的答案,或者更一般地说它只与REST概念相关)。

So my doubt is: what exactly is the HTTP status return code for a successful DELETE statement? 所以我的疑问是:成功的DELETE语句的HTTP状态返回代码究竟是什么?

Is it the 204 or the 200 ? 204还是200

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. 我知道200意味着我的请求得到了正确的实现但是在线阅读在我看来,我希望它在成功获得GET返回内容之后而不是在删除之后。

Somewhere I found that the 204 status is obtained after successful PUT or DELETE . 在某处我发现204状态是在成功的PUT或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? 我无法理解,这意味着响应是空的 ,为什么空响应意味着PUT或DELETE操作成功了?

There are no strict rules on which HTTP status code is the correct one for each method. 对于每种方法,HTTP状态代码是正确的,没有严格的规则。 It depends on what exactly happened, what information you need to send to the client, etc. I can think of a few examples: 这取决于究竟发生了什么,需要向客户发送什么信息等等。我可以想到几个例子:

  • A successful DELETE , with no further information. 一个成功的DELETE ,没有进一步的信息。 204 No Content

  • A successful DELETE , but you have a warning about related orphan resources that should be deleted too. 一个成功的DELETE ,但您有关于应该删除的相关孤立资源的警告。 200 OK . 200 OK

  • You accepted the DELETE request, but it might take a long time and you're going to do it asynchronously. 您接受了DELETE请求,但可能需要很长时间才能以异步方式执行此操作。 The client should check it later. 客户应该稍后检查。 202 Accepted . 202 Accepted

  • You accepted the DELETE request, but the resource can't be removed and the URI is instead reset to a default. 您接受了DELETE请求,但无法删除资源,而是将URI重置为默认值。 205 Reset Content . 205 Reset Content

An empty response body doesn't mean that a delete is successful, a successful delete (usually) means that the response body is empty. 空响应主体并不意味着删除成功,成功删除(通常)意味着响应主体为空。

There's no official status code list for RESTful APIs, but most agree that a 204 is a good response code for a successful delete, as there's usually not a good reason to return a response body after deleting something. RESTful API没有官方状态代码列表,但大多数人都认为204是成功删除的良好响应代码,因为删除内容后通常没有理由返回响应主体。

In general, if an operation is successful and the response body is empty return 204. If an operation is successul and the response body is NOT empty, return 200 通常,如果操作成功并且响应主体为空,则返回204.如果操作是成功的并且响应主体不为空,则返回200

An empty response doesn't mean the operation was successful, the HTTP error code is supposed to indicate success/failure, and the response body may or may not contain data. 空响应并不意味着操作成功,HTTP错误代码应该指示成功/失败,并且响应主体可能包含数据,也可能不包含数据。

The response body may contain additional information regarding the request, eg, a specific message to display to the UI, stats or timing info regarding the information, whatever. 响应主体可以包含关于请求的附加信息,例如,要显示给UI的特定消息,关于信息的统计信息或定时信息等等。 But it doesn't have to, and the body's purpose is informational/diagnostic if it exists. 但它没有必要 ,身体的目的是信息/诊断,如果它存在。

2xx represents the request was successful. 2xx表示请求成功。 The xx just allows for you to be more specific about what happened (what the server did or is returning). xx只允许您更具体地了解发生的事情(服务器执行或返回的内容)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为rest服务中的异常返回http状态码 - How to return http status code for exceptions in rest services 使用Volley获取成功请求的HTTP状态代码 - Get HTTP status code for successful requests with Volley 如何验证返回的状态代码是否成功,即使用 Rest Assured 的任何 2xx HTTP 状态代码? - How to validate if the status code returned is Successful i.e any of the 2xx HTTP status codes using Rest Assured? 返回具有不同 Http 状态的 Rest CompletableFuture - Return Rest CompletableFuture with different Http status 如果在 Rest Api 调用中没有从数据库中找到数据,则返回哪个 HTTP 状态码 - Which HTTP status code to return if there is no data found from database in Rest Api call REST API - HTTP 文件上传,状态码为 415 - REST API - HTTP Fileupload with Status Code 415 哪个HTTP代码应返回为状态? - Which HTTP code should return as status? 没有创建资源时,我应该为POST返回什么HTTP状态代码? - What HTTP status code should I return for POST when no resource is created? 用户尝试从 Db 获取失败数据时返回的 Http 状态错误代码是什么? - What is the Http Status Error code return for user trying failure data from Db? 上载档案时发生错误时,应该返回什么HTTP状态码 - what http status code should be return when we get error while uploading file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM