Pagination in REST Architecture

Suppose we have an endpoint that returns a list of users, the list can be paginated

/ user offset = 20 &? Limit = 10

What to return when the total number of users is less than the offset? An empty list, an error or ...?

Should we also return the total number of users in response? Or should it be another endpoint?

+4
source share
1 answer

I would return an empty array. The url is not technically incorrect. It also makes it easier for the client to handle such cases.

, URL-, .

:

"meta": {
  "cursor": {
    "current": "0",
    "next": "20",
    "count": 20,
    "next_url": "/items?cursor=20&limit=20"
  }
}

, URL- , URL- . .

, OFFSET SQL, , , , . , API , . .

URL- NULL, . , URL- , ( , ).

+4

Source: https://habr.com/ru/post/1677233/


All Articles