本文介绍了如何在REST API中选择“未准备好,稍后再试”的HTTP状态代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个RESTful API,其中 http:// server / thingyapi / thingyblob / 1234 返回与thingy#1234相关联的文件(又名blob)去下载。但可能是请求是在服务器中不存在该文件的情况下进行的,但绝大多数 将在以后可用。服务器中有一个批处理过程,可以为所有东西生成所有blob。 Thingy 1234已经存在,除了blob之外,它的数据已经可用。服务器还没有生成东西1234的blob。

I'm developing a RESTful API in which http://server/thingyapi/thingyblob/1234 returns the file (aka "blob") associated with thingy #1234 to download. But it may be that the request is made at a time the file does not exist in the server but most definitely will be available at a later time. There's a batch process in the server that generates all the blobs for all the thingies. Thingy 1234 already exists and its data, other than the blob, is already available. The server hasn't got to generating thingy 1234's blob yet.

我不想返回404;那是不存在的东西。这是一个存在的东西,但它的blob尚未生成。有点像YouTube视频的处理。我认为重定向代码也不合适;没有其他网址可供尝试。

I don't want to return 404; that's for thingies that do not exist. This is a thingy that exists, but its blob hasn't been generated yet. Kinda like a YouTube video that's "processing." I don't think redirection codes would be proper either; there's no "other" URL to try.

在这种情况下返回的HTTP状态代码是什么?

What's the correct HTTP status code to return in such a case?

推荐答案

我建议 202 - 接受。来自:

这篇关于如何在REST API中选择“未准备好,稍后再试”的HTTP状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:04