“无可用数据”的HTTP状态代码来自外部数据源 [英] HTTP status code for "no data available" from an external datasource
问题描述
情景:
发送 POST
请求以处理订单将导致从外部数据源检索数据。
A POST
request is sent to process an order that will result in data retrieval from an external datasource.
有三种可能的结果:
- 请求的数据源返回数据
- 没有可用于请求的数据(这被视为错误)
- 数据源无法无法访问(可能需要维护)
1 的明显响应是 200:确定
或 201:已创建
(根据此请求创建实体)。
An obvious response for 1 is 200: OK
or 201: Created
(an entity is created from this request).
哪些状态代码适用于 2 和 3 ?
What status codes would be appropriate for 2 and 3?
我考虑的状态代码:
-
503:服务不可用
数据源停止时 -
500:内部服务器错误
数据源关闭时 -
502:错误网关
何时无数据可用 -
404:未找到
当无数据可用时 -
403:禁止$ code>何时无数据可用
-
412:先决条件失败
何时无数据可用
503: Service Unavailable
when datasource is down500: Internal Server Error
when datasource is down502: Bad Gateway
when "no data available"404: Not Found
when "no data available"403: Forbidden
when "no data available"412: Precondition Failed
when "no data available"
推荐答案
2)回过头来看,我同意它应该是204 No Content或者200根据返回的结构,可以找到指示没有记录或资源的正文。
404通常在资源URI不存在时使用,或者在restful服务的情况下找不到URI中的资源。
2) Looking back at this, I agree it should probably be either a 204 No Content or maybe a 200 with a body indicating no records or resources could be found depending on the structure returned. 404's are generally used when the resource URI doesn't exist or a resource in the URI is not found in the case of a restful service.
3) 503服务不可用
3) 503 Service Unavailable
由于服务器临时过载或维护,服务器当前无法处理请求。这意味着这是一个暂时的条件,经过一段时间的延迟后会得到缓解。如果已知,延迟的长度可以在Retry-After报头中指示。如果没有给出Retry-After,客户端应该像处理500响应一样处理响应。
The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.
Note: The existence of the 503 status code does not imply that a
server must use it when becoming overloaded. Some servers may wish
to simply refuse the connection.
这篇关于“无可用数据”的HTTP状态代码来自外部数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!