Pagination 101: why it matters and how to do it right in your API

As per the API spec in the first section, The primary reason for exposing a HEAD endpoint and the pageable GET resource is to simplify the process of looping through the pages. You may use the HEAD endpoint to retrieve the record count and, based on that, you can use MuleSoft for each scope to loop through the pages. This HEAD endpoint also serves for the needs where you want to send summary information to the consumer about your dataset. The above method is very convenient but if we have multiple APIs where pagination is required, then this process becomes hectic and tedious. So let’s create a middleware to handle pagination in any API endpoint. Another is that you can move things like the next() and previous() methods you’re likely to need (to allow actual paging) into the PagingSpecification classes as well, and share yet more code.

Pagination works well when you know the size of the data in advance, and you don’t make frequent additions or deletions to the data-set. Developer.com features tutorials, news, and how-tos focused on topics relevant to software engineers, web developers, programmers, and product managers of development teams. In addition to covering the most popular programming languages today, we publish reviews and round-ups of developer tools that help devs reduce the time and money spent developing, maintaining, and debugging their applications. This includes coverage of software management systems and project management (PM) software – all aimed at helping to shorten the software development lifecycle (SDL).

Connecting APIs to databases: the perfect pairing for powerful applications

To see this in action, there’s an additional field in the example schema, called friendsConnection, that exposes all of these concepts. Try removing the after parameter to friendsConnection to see how the pagination will be affected. Also, try replacing the edges field with the helper friends implementing pagination field on the connection, which lets you get directly to the list of friends without the additional edge layer of indirection, when that’s appropriate for clients. Small data sets do work on effectively on offset pagination but large realtime datasets do require cursor pagination.

implementing pagination

It includes supporting local and national officials as they work to strengthen Ecuador’s border and maritime security. And it includes investigating and prosecuting the sophisticated criminal networks that https://deveducation.com/ perpetrate crime and violence, and threaten Ecuador’s democratic institutions. This includes setting up the country’s first-ever Specialized Court for Organized Crime and Corruption, for example.

Understanding Pagination

You can adjust the cursor or offset to skip over deleted data or include newly inserted data, depending on the situation. Additionally, caching the data and pagination results can help improve API performance and ensure consistency, but it should be done carefully to avoid issues. Pagination is a technique for breaking up large datasets into smaller, more manageable chunks.

  • So let’s create a middleware to handle pagination in any API endpoint.
  • One of the more popular is the Hibernate ORM solution for Java, which comes with support for most database flavors, and has internal caching.
  • Many modern web frameworks also come with the pagination algorithm hooks, or ready-to-use modules.
  • One problem may be if you add a data item, but based on your description it sounds like they would be added to the end (if not, let me know and I’ll see if I can improve on this).
  • It’s a well-known statistic that 53% of web users will abandon a web page if it takes more than 3 seconds to load.
  • The database can directly fetch the records from the disk by looking up the address in the database index for the given unique identifier value.

Leave a Reply