开发者

Can you build a truly RESTful service that takes many parameters?

开发者 https://www.devze.com 2023-02-18 13:51 出处:网络
After reading an article on REST (\"Restful Grails\"), I have gotten the impression that it is not possible to truly conform to a REST style in a service that demands a lot of parameters. Is this so?

After reading an article on REST ("Restful Grails"), I have gotten the impression that it is not possible to truly conform to a REST style in a service that demands a lot of parameters. Is this so? All the examples I have seen so far seem to imply that true REST style services are "parameterless". Using parameters would be RPC-ish and not truly RESTful.

To be more specific, say we have a service that returns graph data for stock prices, and this service needs to know the start date, end date, the currency, stock name, and whatever else might be applicable. In any case, at least 4-5 parameters are needed to retrieve the information needed. I would imagine the URL to be something like this : /stocks开发者_开发百科/YAHOO?startDate="2008-09-01"&endDate=... ("YAHOO" is here a made-up stock name).

Would this really be REST or is this more RPC-like, what the author of the aforementioned article calls "GETful" (i.e. just low ceremony rpc)?


You can see the querystring as a filter on the resource you are GETing. Here, your resource is the stock prices of yahoo. Doing a GET on that resource give you all the available data, or the most recents. The query string filter the prices you want. Content negociation allow you to change the representation, e.g. a png graph, a csv file, and so on. To add a price, simply POST a representation (e.g. CSV) to the same resource.

The "restfulness" is not realy in the URL itself, since URIs are obscures to client, but in the way you interact with resources themselves identified by their URI


Feel free to use as many parameters as you need to identify the resource you wish to access. REST doesn't care.


Why would you think it is not possible?

Google uses REST for their charts api, and they take alot of params:

http://chart.apis.google.com/chart?cht=bvg&chs=350x300&chd=t:20,35,10&chxr=1,0,40&chds=0,40&chco=FF0000|FFA000|00FF00&chbh=65,0,35&chxt=x,y,x&chxl=0:|High|Medium|Low|2:||Task+Priority||&chxs=2,000000,12&chtt=Tasks+on+my+To+Do+list&chts=000000,20&chg=0,25,5,5

0

精彩评论

暂无评论...
验证码 换一张
取 消