简体   繁体   English

如果没有可用数据,应该返回什么http

[英]What http return code should be if no data available

For example i have an api method /api/orders.getOrders which actually always exists. 例如,我有一个实际上总是存在的api方法/api/orders.getOrders If this method returns no data in following format, should i send 404 or 200 http response code? 如果此方法不返回以下格式的数据,我应该发送404或200 http响应代码吗?

{ "orders":[] }

200 is correct. 200是正确的。

From RFC 7231 来自RFC 7231

The 4xx (Client Error) class of status code indicates that the client seems to have erred. 状态代码的4xx(客户端错误)类表示客户端似乎有错误。

The 404 (Not Found) status code indicates that the origin server did not find a current representation for the target resource 404(未找到)状态代码指示源服务器未找到目标资源的当前表示

In your case, the client did not make a mistake in asking for the resource; 在你的情况下,客户端没有犯错误的请求的资源; the origin server did find a current representation of the resource, so 404 (indeed, the entire 4xx class of responses) is not appropriate. 原始服务器确实找到了资源的当前表示,因此404(实际上,整个4xx类响应)不合适。

204 is also wrong . 204也错了

The 204 (No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body. 204(无内容)状态代码表示服务器已成功完成请求,并且在响应有效负载主体中没有要发送的其他内容。

"No content" means that the HTTP response message body is empty, which is to say the representation being returned is 0 bytes long. “无内容”表示HTTP响应消息体是空的,也就是说返回的表示是0字节长。 It's not appropriate when returning a non empty representation of an empty resource. 返回空资源的非空表示时,这是不合适的。

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

相关问题 没有数据时应返回哪个http代码 - Which http code should return when there is no data 如果资源不可用于请求的操作,HTTP状态代码应该是什么? - what should be HTTP status code if resource is not available for requested action? 我应该对可能返回陈旧数据的GET请求使用什么HTTP状态代码? - What HTTP status code should I use for a GET request that may return stale data? 我应该返回什么 HTTP 状态响应码? - What HTTP status response code should I return? 对于在 202 代码后未准备好的资源,REST 应返回什么 HTTP 代码? - What HTTP code should REST return for a resource that is not ready after a 202 code? 哪个HTTP代码应返回为状态? - Which HTTP code should return as status? 如果Web API同时执行UPDATES和INSERTS,则在成功完成后应该返回什么HTTP状态代码? - What HTTP status code should a Web API return after successful completion, if it performed both UPDATES and INSERTS? 没有创建资源时,我应该为POST返回什么HTTP状态代码? - What HTTP status code should I return for POST when no resource is created? 应该将哪些4xx HTTP返回码用于私有API错误响应? - What 4xx HTTP return code should be used for private API error responses? 当进程运行时请求被拒绝时,我应该返回什么 http 代码? - What http code should I return when the request is rejected while process is running?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM