对于 202 代码后未就绪的资源,REST 应返回什么 HTTP 代码?

发布于 2024-11-10 03:02:02 字数 142 浏览 6 评论 0原文

似乎无法在任何地方找到这个问题的答案。有一个服务,当发布某些内容时,它会排队等待处理,响应代码为 202。标准说提供一个指向状态监视器的指针,我已经这样做了,但是如果客户端转到在资源准备好之前资源?我认为404除了资源存在之外,只是还没有被处理。

想法?

Can't seem to find the answer to this question anywhere. Have a service that when something is posted, it gets queued to be processed with a response code of 202. The standard says to provide a pointer to a status monitor, which I have done, but what should I return if the client goes to the resource before the resource is ready? I would think 404 except that the resource exists, just hasn't been processed yet.

Thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青芜 2024-11-17 03:02:02

检查帖子:

当客户端稍后检查状态 URI 时,如果该项目仍处于待处理状态,则状态 URI 可能会返回 200 OK 响应以及描述此情况的实体主体。如果资源已创建,则状态 URI 可能会返回 201 Created 响应,其中包含指向新资源位置的 Location 标头。如果由于某种原因未创建该项目,则状态 URI 可能会返回 410 Gone 响应。在这种情况下,您应该包含一个实体主体来解释资源消失的原因,即“由于处理错误,我们无法创建此资源”。 404 Not Found 响应也是可以接受的,但 410 Gone 响应意味着永久性;请求的资源永远消失了。

对我来说似乎相对合理,除了 Location 标头 IMO 并不特别适合这个确切的目的。

Check this post:

When the client checks the status URI later, if the item is still pending then the status URI might return a 200 OK response with an entity body describing this. If the resource has been created, then perhaps the status URI would return a 201 Created response with a Location header pointing to the location of the new resource. If the item was not created for some reason, then perhaps the status URI would return a 410 Gone response. In this case, you should include an entity body explaining why the resource is gone, i.e. “We were unable to create this resource due to processing errors.” A 404 Not Found response would also be acceptable, but the 410 Gone response implies permanence; the requested resource is gone for good.

Seems relatively reasonable to me, except that Location header IMO is not particularly suited for this exact purpose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文