对于多页结果,REST URI 的良好设计是什么?
假设我有一个想要通过 REST 公开的服务。 对服务的查询可能会产生一长串结果,这些结果将“逐页”返回,这就是为什么用户必须能够:
- 指定排序标准(对一个属性或另一个属性的值进行字母排序)
- 指定一个从哪里获取结果的键值:“显示来自字母 C 的结果...”
- 指定开始获取结果的页码(即我想从第 3 页获取结果)
- 指定每页的最大结果数
我认为排序标准非常适合查询字符串参数,因为它不属于资源,而只是对其返回的表示的偏好。
其他选项又如何呢?整个想法是否合理,或者它是否带有太多面向网络的起源?
作为旁注,对于具有多页结果的繁重查询,您是否有任何良好的整体设计建议(例如在服务器上缓存结果的策略)?
谢谢。
Say I have a service I want to expose via REST.
A query on the service may yield a long list of results, which are returned "page by page", which is why the user must be able to:
- specify an ordering criterion (alpha sorting on the values of one attribute or another)
- specify a key value from where to get results: "show me results from letter C on..."
- specify a page number from which to start getting results (i.e. I want to get the results from page 3 )
- specify the max number of results per page
I suppose the ordering criterion is well suited to a query string parameter, since it does not belong to the resource, but is just a preference for its returned representation.
What about the other options? Is the whole idea sound, or it smells too much of its web-oriented origin?
As a side note, have you got any pointers for good overall design suggestions for heavy queries with multiple pages of results (for example policies for caching results on the server)?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 RESTful Web 服务手册:
请求
响应
From RESTful Web Services Cookbook:
Request
Response