Can you build a truly RESTful service that takes m

2019-07-20 07:32发布

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)?

3条回答
神经病院院长
2楼-- · 2019-07-20 07:55

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

查看更多
叼着烟拽天下
4楼-- · 2019-07-20 08:06

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

查看更多
登录 后发表回答