Module 47: REST API Design

Lesson 4 of 5 ยท 15โ€“25 minutes

Pagination

๐Ÿ The everyday picture

A phone book is split into pages. Nobody photocopies the whole book to find one number.

๐Ÿ“˜What it really is

{
  "data": [ ... ],
  "page": 3,
  "pageSize": 25,
  "total": 412
}

๐Ÿ–ฑ๏ธTry it

Add offset pagination to GET /enquiries, with a default of 25, maximum 100, and total in the response. Validate the parameters. Connect the React table's pagination from Module 40 to it.

โœ…Quick check

Why set a maximum page size?

Show the answer

So nobody can request huge pages that overload the server or database.

An inbox shows newest first and new enquiries arrive constantly. Offset or cursor pagination?

Show the answer

Cursor pagination, which stays stable while new items are added.

โ† PreviousMethods, idempotency and status codes
ProLearners Assist