REST api pagination: make page-size a parameter (configurable from outside)

manuel aldana picture manuel aldana · Jan 6, 2010 · Viewed 12.7k times · Source

we are having a search/list-resource:

http://xxxx/users/?page=1

Internally the page-size is static and returns 20 items. The user can move forward by increasing the page number. But to be more flexible we are now thinking also to expose the size of a page:

http://xxxx/users/?page=1&size=20

As such this is flexible as the client can now decide network-calls vs. size of response, when searching. Of course this has the drawback that the server could be hit hard either by accident or maliciosly on purpose: http://xxxx/users/?page=1&size=1000000

For robustness the solution could be to configure an upper limit of page size (e.g. 100) and when it is exceeded either represent an error response or a HTTP redirect to the URL with highest possible page-size parameter.

What do you think?

Answer

Nate picture Nate · Jan 6, 2010

Personally, I would simply document a maximum page size, and anything larger than that is simply treated as the maximum.