使用*多个*参数调用 RESTful 服务 [英] Calling a RESTful service with *many* parameters

查看:59
本文介绍了使用*多个*参数调用 RESTful 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在设计一个 iPhone 应用程序,它将回调在 Tomcat 中运行的 RESTful 服务.我们需要发送很多查询参数并且已经超过了手机允许的最大值.

WE are designing an iPhone app that will call back to a RESTful service running in Tomcat. We need to send many query parameters and have exceeded the maximum that the phone will allow.

使用带有主体中参数的 PUT 调用是否是 RESTful,即使意图不修改服务器?POST 似乎不正确,因为它不是幂等的,而 PUT 是(因此更类似于 GET 的行为).

Would it be RESTful to use a PUT call with the parameters in the body, even though the intent in not to modify the server? A POST does not seem correct because it is not idempotent, while a PUT is (and thus more closely resembles the behavior or of a GET).

谢谢.

推荐答案

如果你想要 RESTful,你可以这样做:将参数放到服务器(在你选择的位置),或者你可以 POST它们并让服务器为您放置它们.无论哪种方式,您都刚刚创建了一个包含所需参数的资源.然后您发送一个 GET 引用该特定资源.在回答您的 GET 时,服务器因此知道从哪里获取其大量参数.那将是 RESTful.

If you want it RESTful, you could go about it this way: PUT the parameters to the server (at a location of your choosing), or you could POST them and let the server place them for you. Either way, you have just created a resource that holds the parameters you need. Then you send a GET referring to that particular resource. In answering your GET, the server therefore knows where to get its large set of parameters. That would be RESTful.

不过,如果您可以用一个请求做同样的事情,那么发送两个请求的效率并不高.我只是尝试务实.

That said, however, sending two requests isn't very efficient, if you can do the same thing with a single request. I'd just try to be pragmatic.

考虑一下:PUT 告诉代理他们不应该缓存响应,但是重试(通过线路中的任何基础设施元素)绝对是可能的,因为它是幂等的(就像 GET).GET 比 PUT 给你什么?响应可以被缓存.但是有了这么多参数,我会假设大多数请求无论如何都是唯一的,对吧?因此,缓存不会经常带来太多回报.因此,使用 PUT 似乎是务实的,也是正确的选择.

Consider this: PUT tells proxies that they shouldn't cache the response, but a retry (by any infrastructure element along the line) is definitely possible, since it's idempotent (just like GET). What does GET give you over PUT? The response can be cached. But with that large number of parameters, I would assume that most requests will be unique anyway, right? So, caching isn't going to deliver much pay off very often. Therefore, using PUT seems to be the pragmatic, and thus the correct choice.

这篇关于使用*多个*参数调用 RESTful 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆