4

我为我的同事设计了一个图像处理 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 响应的正确方法吗?

4

1 回答 1

1

我认为如果您只是将 URL 留在http://abc.com:8080/api/v0/compare-19没有重定向的 200 OK 响应中会更好。让响应的 resultImage 是图像的相对/绝对 URL。然后客户端可以获取有关操作的元数据,如果他们想获得最终的结果图像,可以按照 resultImage URL。

于 2013-01-18T01:36:38.920 回答