REST Web 应用程序中的分页 - Pagination in a REST web application

问题:

This is a more generic reformulation of this question (with the elimination of the Rails specific parts)这是这个问题的更通用的重新表述(消除了 Rails 特定部分)

I am not sure how to implement pagination on a resource in a RESTful web application.我不确定如何在 RESTful Web 应用程序中的资源上实现分页。 Assuming that I have a resource called products , which of the following do you think is the best approach, and why:假设我有一个名为products的资源,您认为以下哪种方法是最好的,为什么:

1. Using only query strings 1. 仅使用查询字符串

eg.例如。 http://application/products?page=2&sort_by=date&sort_how=asc
The problem here is that I can't use full page caching and also the URL is not very clean and easy to remember.这里的问题是我不能使用整页缓存,而且 URL 不是很干净且易于记忆。

2. Using pages as resources and query strings for sorting 2. 使用页面作为资源和查询字符串进行排序

eg.例如。 http://application/products/page/2?sort_by=date&sort_how=asc
In this case, the problem that is see is that http://application/products/pages/1 is not a unique resource since using sort_by=price can yield a totally different result and I still can't use page caching.在这种情况下,所看到的问题是http://application/products/pages/1不是唯一资源,因为使用sort_by=price会产生完全不同的结果,我仍然无法使用页面缓存。

3. Using pages as resources and an URL segment for sorting 3. 使用页面作为资源和一个 URL 段进行排序

eg.例如。 http://application/products/by-date/page/2
I personally see no problem in using this method, but someone warned me that this is not a good way to go (he didn't give a reason, so if you know why it's not recommended, please let me know)我个人认为使用这种方法没有问题,但有人警告我这不是一个好的方法(他没有给出理由,所以如果你知道为什么不推荐,请告诉我)

Any suggestions, opinions, critiques are more than welcome.任何建议、意见、批评都非常受欢迎。 Thanks.谢谢。


解决方案:

参考一: https://en.stackoom.com/question/3FzM
参考二: https://stackoom.com/question/3FzM
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章