ROHINI, DELHI · LIVE ONLINE & CLASSROOM

REST API pagination test worksheet

A request returns two records and a success status. Has your client read the whole collection? A pagination test answers that question by checking how a client moves between result pages and how it knows when to stop. A successful first response is only the beginning of the exercise.

This worksheet uses an original fictional API with saved response fixtures. No public service is called, no account token is needed and no real learner or customer data is used. Run it in a disposable local practice project. Confirm the actual endpoint contract before applying these cases to another API.

Write the contract before the loop

Our invented endpoint returns a JSON object with two fields: items, an array of records with stable id values, and next, either an opaque page token or null. A null token is the only normal completion signal in this exercise. The fixtures stay unchanged during each run, so their expected record set is known.

That is a teaching contract, not a REST standard. Real services can use page numbers, cursors or response links. GitHub's pagination reference, for example, describes following the next-page URL in a Link header and checking an endpoint's supported page-size parameters. Its rules should not be assumed for an unrelated API.

Copy the three-page fixture

start: items [A1, A2], next "p2"
p2:    items [A3, A4], next "p3"
p3:    items [A5],     next null

The labels A1 through A5 are invented record IDs. Before coding, write the expected request sequence: start, p2, p3. Write the expected collected IDs: A1, A2, A3, A4, A5. The final page contains fewer items, but the reason to stop is its null next token. A short page alone is not the completion rule.

For each response, capture the requested token, returned IDs, next token and completion state. Keep prediction separate from observation. An implementation that prints five IDs but quietly makes another request has not met the stated sequence check.

Use boundary cases that expose assumptions

Saved fixtureExpected observation under this contract
Empty first page, next nullOne request, no records, completed.
One full page, next nullStop after that page, even though it is full.
Short first page, next p2Follow p2; short does not mean finished.
Empty middle page, next p3Continue to p3; the token controls progress.
p2 returns next p2Detect the repeated token, stop safely and report an incomplete result.
Page two failsPreserve the failure and partial count; do not label the collection complete.

The empty-middle case is deliberately allowed by this fictional contract. Another endpoint may prohibit it. The purpose is to expose a client that invents completion from array length instead of following its documented rule. Keep the contract and fixture together so that a failed expectation can be reviewed.

Keep progress protection separate from success

Record tokens already requested and set a bounded request limit for the local exercise. A repeated token or exhausted limit should produce an explicit incomplete outcome. Stopping an infinite loop protects the exercise; it does not prove that every record was fetched.

Choose a request limit that permits all saved test pages. Document it rather than treating an arbitrary number as a safe production default. A real client's limits, retry behaviour, authentication and permitted destinations belong in its implementation design. This worksheet authorises no changes to a production integration.

Check identity as well as total count

Now replace A3 on the second page with A2. The raw list still contains five entries, but only four distinct IDs. Record both the raw and distinct counts, then compare the actual IDs with the expected fixture set. Five entries are not evidence that A1 through A5 were each retrieved once.

Do not silently remove duplicates and declare the defect fixed. In this static fixture, a repeated ID is a test finding to explain. On a changing real collection, records can move while pages are fetched; stable ordering and snapshot behaviour need the endpoint's own documented guarantees. This exercise demonstrates neither a universal no-duplicates rule nor exactly-once retrieval for live data.

Make a failed page visible in the result

For the failure fixture, let the first response succeed and the second return a saved error. Your observation note should identify the failed page and the two IDs obtained so far. Preserve the error category without copying credentials or private response bodies into a public report.

This exercise does not implement automatic retry. A real retry policy must consider the service contract, limits and operational requirements. A later successful request should be recorded as new evidence. It should not erase the original interruption or turn an earlier partial export into a complete one retrospectively.

Prepare a compact review record

Use columns for fixture name, expected token sequence, observed sequence, raw IDs, distinct IDs, termination reason and complete or incomplete. Add the code revision and local runtime version. Someone else should be able to rerun the same saved inputs and understand why you accepted or rejected the result.

A fictional finding might read: “The short first page has next p2, but the client stopped after one item. Expected continuation was not attempted.” That is more useful than “pagination broken”, and more honest than “all records fetched” based only on a success status. Keep the smallest reproducing fixture beside the finding.

Common questions

Does HTTP success prove collection completeness? It describes that response; completeness needs the endpoint's continuation and termination checks. Can I guess the next cursor? Treat this exercise's token as opaque and follow the returned value. Must every API behave like these fixtures? No. Adapt expected cases to its actual contract.

Compare this with the small API validation tests, which focus on request inputs, and ask about practical API learning. This is an independent learning worksheet, not a promise that every course includes a particular assignment.

Admissions

Request a call back

Tell us which course you are interested in and the counselling desk will call you about fees, batches and a free demo class.

18008913982 (toll free) · +91 9899-355-335
[email protected]

Message us on WhatsApp

Open the enquiry form in a separate window ↗

Your enquiry goes to Coding Bytes through ViaCRM so the counselling team can respond. Please share only the details needed for your question, not passwords, payment details or sensitive documents. Privacy & enquiries · Before enrolling

Call WhatsApp Enquire