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