RESTful Design: Paging Collections

后端 未结 3 804
遇见更好的自我
遇见更好的自我 2021-02-04 06:57

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:

Optio

相关标签:
3条回答
  • 2021-02-04 07:41

    I'd go with option (2). Why?

    1. You can later add page-size parameter to the query so the client can specify the page size.
    2. In case no page parameter was specified you can just return the first page (the default). In many cases you client might need only the first page, so it simplifies the protocol between client and server.
    0 讨论(0)
  • 2021-02-04 07:55

    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.

    0 讨论(0)
  • 2021-02-04 07:59

    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

    0 讨论(0)
提交回复
热议问题