Skip to main content
Back to Dev generators

Dev

Mock Pagination Response Generator

Pagination bugs are among the most common API integration issues — the last page returning fewer items, a page beyond total count returning an error, or has_next showing true when it should be false. A mock pagination response generator lets you reproduce any of these scenarios instantly without a live API. Three inputs control the output. Items per page sets the page size (1–50). Current page sets which page to simulate (1–100). Total items sets the full dataset size (1–10000). The generator computes total_pages, from and to (item index range), has_next and has_prev, and next_page and prev_page. The data array contains user-like objects matching the actual item count for the simulated page. For the last-page edge case: set total items to 97 and page size to 10, then request page 10 to get 7 items and has_next false.

Read the complete guide — 4 min read

How to use

  1. Choose your options above
  2. Click Generate
  3. Copy your result

Detailed instructions

  1. Set 'Items per Page' to the page size your real API will use, such as 10, 25, or 50.
  2. Enter the 'Current Page' number you want to simulate, starting at 1 for the first page.
  3. Set 'Total Items' to your expected dataset size, including odd numbers to test partial last pages.
  4. Click Generate to produce a complete JSON response with all pagination metadata computed.
  5. Copy the output and paste it into your test fixture, MSW handler, or API documentation example.

Use Cases

  • Populating a TanStack Table or AG Grid component before the backend API exists
  • Creating MSW (Mock Service Worker) handler responses for paginated REST endpoints
  • Testing last-page partial-item behavior with 97 total items and 10 per page in Vitest
  • Generating JSON Server fixture files to power local development with realistic pagination
  • Writing accurate, runnable pagination examples in OpenAPI or Postman collection documentation

Tips

  • Test page 1, a middle page, and the exact last page separately — UI bugs often appear only at boundaries.
  • Use a total like 101 with page size 10 to force an 11-page scenario and quickly spot off-by-one errors in your page count display.
  • If your framework uses 0-indexed pages internally, generate with page 1 and adjust the current_page value in your fixture before committing.
  • Pair the generated JSON with MSW's runtime handler so different page parameters return different generated responses without maintaining multiple files.
  • Set total items to 0 to generate an empty-state response and verify your UI shows the correct 'no results' message instead of broken pagination controls.
  • Match your real API's field naming conventions — if your backend uses camelCase (totalPages vs total_pages), do a quick find-and-replace on the output before using it in tests.

FAQ

how do I mock a paginated API response for Jest or Vitest tests

Generate a response with your desired page size, current page, and total items, then paste the JSON into a fixture file or inline it as your API mock's resolved value using jest.fn().mockResolvedValue() or vi.fn(). Fields like total_pages and has_next are already computed, so your assertions can check pagination state without extra setup.

how do I simulate the last page returning fewer items than the page size

Set total items to a number that does not divide evenly by page size — for example, 97 items with 10 per page — then set current page to 10. The generator returns 7 items in the data array, sets has_next to false, and calculates the correct from/to range. This catches UI bugs that only surface on the final page.

what is the difference between the from/to fields and the page/per_page fields

page and per_page describe the pagination parameters. from and to are derived fields showing the absolute item index range on the current page — for example, items 21 to 30 on page 3 of a 10-per-page result set. Most table UIs display 'Showing 21–30 of 97 results' directly from these fields without any extra calculation.

what happens if I set current page higher than total pages

The generator clamps current_page to total_pages and returns the last page's items correctly — accurate item count, has_next false, next_page null, and correct from/to values. This lets you test how your client handles out-of-bounds page requests without getting a broken response.

You might also like

Popular tools from other categories that share themes with this one.

Try these next

More free tools from other corners of the catalog, picked by shared themes.