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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章