这是显示图像的REST合规方式吗?

时间:2013-01-17 20:23:39

标签: java ruby rest

我为我的同事设计了一个图像处理API。他使用Ruby(RestClient)作为客户端。

$ curl -i -X GET http://abc.com:8080/api/v0/compare-19
HTTP/1.1 303 See Other
Date: Thu, 10 Jan 2013 08:02:02 GMT
Content-Type: application/json
Location: http://abc.com:8080/result/856caf71-df10-4b9e-a981-4785de2f4854.png
Transfer-Encoding: chunked
Server: Jetty(8.1.3.v20120416)

{
    "id": 19,
    "state": "completed",
    "timestamp": "2013-01-10T00:01:13.755-08:00",
    "resultImage": "856caf71-df10-4b9e-a981-4785de2f4854.png",
    "passcode": "AXBD"
}

他希望捕获“状态”和“密码”,但根据RESTClient文档,ruby程序会立即重定向到http://abc.com:8080/result/856caf71-df10-4b9e-a981-4785de2f4854.png

Exceptions (see www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
for results code between 200 and 207 a RestClient::Response will be returned
for results code 301, 302 or 307 the redirection will be followed if the request is a get or a head
for result code 303 the redirection will be followed and the request transformed into a get
for other cases a RestClient::Exception holding the Response will be raised, a specific exception class will be thrown for know error codes

我的问题是,这是否是提供REST响应的正确方法?

1 个答案:

答案 0 :(得分:1)

我认为如果您将http://abc.com:8080/api/v0/compare-19处的网址保留为没有重定向的200 OK响应会更好。让响应的resultImage成为图像的相对/绝对URL。然后,客户端可以获取有关操作的元数据,如果想要获取最终结果图像,请遵循resultImage URL。