Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

rest

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?

like image 307
manuel aldana Avatar asked Jan 06 '10 20:01

manuel aldana


People also ask

Which method is considered most efficient for pagination in REST API?

The Offset method is the most common way to paginate resources (with an offset on query), but it's less efficient than the Search-after method.

What is PageSize in pagination?

PageSize : represents the number of records that are displayed when a page loads. PageSizes : represents the different page sizes that the user can select.

What are pagination parameters?

Pagination can be implemented using one or both of two query parameters: limit to define the number of items returned in the response, and. marker to specify the ID of the last seen item.

Should I Paginate my API?

API pagination is essential if you're dealing with a lot of data and endpoints. Pagination automatically implies adding order to the query result. The object ID is the default result, but results can be ordered in other ways as well.


1 Answers

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

like image 195
Nate Avatar answered Sep 20 '22 03:09

Nate