Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful Design: Paging Collections

I am designing a REST api that needs paging (per x) enforces from the server side.

What would be the right way to page through any collection of resources:

Option 1:

GET /resource/page/<pagenr>
GET /resource/tags/<tag1>,<tag2>/page/<pagenr>
GET /resource/search/<query>/page/<pagenr>

Option 2:

GET /resource/?page=<pagenr>
GET /resource/tags/<tag1>,<tag2>?page=<pagenr>
GET /resource/search/<query>?page=<pagenr>

If 1, what should I do with GET /resource? Redirect to /resource/page/0, reply with some error or reply with the exact same as /resource/page/0 without redirecting?

like image 748
Koen Bok Avatar asked Feb 01 '09 15:02

Koen Bok


2 Answers

What the URI looks like is not the most important part. What you should be thinking about instead is how it is presented to the user. A page should for example have a link to the "next" page and another link to the "previous" page (if there is one). Take a look at RFC 5005 Feed Paging and Archiving

like image 95
Bjorn Avatar answered Sep 20 '22 18:09

Bjorn


With my limited understanding of what REST is about, then the following might be the "most" restful.

GET /resource/?page=<pageenr>&asof=<datetime>

Since the content of the representation would never change unexpectedly, and caching could be used.

But to actually answer your question, I think the parameter page is the preferred method.

like image 37
Allain Lalonde Avatar answered Sep 21 '22 18:09

Allain Lalonde