Http 响应 303 是否暗示客户端需要重定向?

Does Http response 303 imply client is required to redirect?

我正在实施 API,试图坚持 Restful 设计。我们有一个用例来接受 POST 请求,创建资源并 return 一个 URL 给客户端。客户端将希望应用一些业务逻辑来确定是否应该从 URL 中检索资源。对我来说,return 代码应该是 303 似乎很自然,正如 RFC 7231 所指定的:

A user agent can perform a retrieval request targeting that URI (a GET or HEAD request if using HTTP), which might also be redirected, and present the eventual result as an answer to the original request

但是,一位同事不同意并提出了 200 响应,因为不应要求客户端遵循重定向来获取资源 - 这取决于他们。 RFC 声明

If a Location header field (Section 7.1.2) is provided, the user agent MAY automatically redirect its request to the URI referenced by the Location field value, even if the specific status code is not understood. Automatic redirection needs to done with care for methods not known to be safe, as defined in Section 4.2.1, since the user might not wish to redirect an unsafe request

我读到这个是说重定向响应将是否重定向的决定权留给了客户端。我的同事争辩说,由于浏览器和客户端会自动重定向,我们不应该指示他们这样做。这是正确的吗?

REST APIs 的正常约定是不在 POST 之后重定向,APIs 不需要 PRG 模式。

HTTP 状态代码应该反映已完成的操作(200,201,202 等)而不是重定向状态代码,因为这对 API.

的消费者更友好

浏览器确实 follow redirects,所以通过重定向,您会更难从浏览器中使用您的 API - 他们无法决定不遵循重定向。