How do you implement pagination in an API?

REST API design and errors · Freshers and experienced

Model answer

Offset pagination uses page and limit (skip((page-1)*limit).limit(limit)), which is simple but slows down on deep pages and can skip items when data changes. Cursor pagination returns items after a cursor such as the last id, which is faster and stable for feeds. Return metadata such as total and next page, and cap the maximum limit.

Learn this topic

Build a REST API: Create, Read, Update and Delete Tasks in the course Node.js and Express: Build a Back End API from Scratch.

Sign in to add your own answer.

More questions