当服务器返回 202 - Accepted
时,给出请求完成估计的适当方法是什么?异步请求的状态码?
来自 HTTP spec (斜体是我加的):
202 Accepted
The request has been accepted for processing, but the processing has not been completed. [...]
The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.
以下是一些想法:
Cache-Control
? X-
响应头,但 X-
标题已在 RFC 6648 中弃用? X-
)特定的响应 header ?如果是,应该如何命名? SO 问题 Custom HTTP headers : naming conventions给出了一些想法,但在弃用之后,它只回答了 HTTP header 的格式,而不是它们应该如何命名。 最佳答案
绝对不要为此滥用现有的 HTTP header 。由于它是您自己的服务器,您可以定义响应的外观。您可以(并且应该)选择最适合此信息的预期接收者的任何响应,并在响应正文中返回实际信息。
例如,如果您只对显示人类可读的消息感兴趣,那么您可以返回 text/plain
说“您的请求可能会在接下来的 30 分钟内得到处理。”。
在频谱的另一端,您可能想要完全采用 REST 方式并返回 application/json
,也许格式是这样的(我完全是当场编造的):
{
"status": "pending",
"completion": {
"estimate": "Thu Sep 08 2011 12:00:00 GMT-0400",
"rejected-after": "Fri Sep 09 2011 12:00:00 GMT-0400",
},
"tracking": {
"url": "http://server/status?id=myUniqueId"
}
}
关于rest - HTTP 状态 202 - 如何提供有关异步请求完成的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14832983/