Dev

Mock Pagination Metadata Generator

The mock pagination metadata generator creates realistic API pagination blocks in multiple formats — JSON, HTTP Link headers, and full envelope structures — so you can test pagination logic without wiring up a real backend. Pagination is one of the trickiest patterns to get right in REST APIs because edge cases multiply fast: first page with no previous link, last page where items don't fill the page, single-page results where pagination should disappear entirely. Testing these scenarios requires varied, realistic metadata, not hand-typed placeholder values. This generator covers the three formats teams actually use in production. JSON-style pagination objects drop directly into response fixtures for Jest or Vitest tests. Link header output matches RFC 5988 format, which is what GitHub's API uses and what libraries like React Query and SWR can parse natively. Envelope format wraps a data array alongside meta and links objects, matching patterns popularized by JSON:API and Laravel's paginator. Frontend developers can paste the output into Storybook stories to render pagination components against realistic data. Backend developers can use generated examples as contract fixtures in Pact or OpenAPI specs. QA engineers can seed Postman mock servers with multiple page states to verify that UI components respond correctly to boundary conditions like empty pages or single-result sets. Set the count input to control how many distinct pagination metadata blocks are generated at once, which is useful when you need to simulate a user clicking through several pages in sequence. Adjust the format selector to match your API's actual response structure, then copy the output directly into your test fixtures, mock server, or documentation.

How to Use

  1. Select the format that matches your API: JSON, Link Header, or Envelope.
  2. Set the count field to the number of pagination blocks you need, typically four to eight for full page-state coverage.
  3. Click Generate to produce the metadata blocks.
  4. Copy individual blocks and paste them into your fixture files, Postman examples, or OpenAPI spec.
  5. For sequential page simulation, assign blocks in order from first to last page in your test setup.

Use Cases

  • Seeding Postman mock servers with multi-page API response fixtures
  • Writing Storybook stories for pagination UI components with realistic data
  • Generating OpenAPI example objects for paginated list endpoints
  • Creating Pact contract test fixtures for consumer-driven API testing
  • Testing React Query or SWR cursor handling with RFC 5988 Link headers
  • Simulating edge cases like single-page results or empty last-page responses
  • Populating API documentation with concrete paginated response examples
  • Unit testing backend pagination helpers against realistic total and offset values

Tips

  • Generate exactly four blocks and label them first-page, mid-page, last-page, and single-page to cover every pagination boundary condition in one pass.
  • When using Link header format, run the output through the npm package parse-link-header locally to verify your parsing code handles it before wiring up tests.
  • For Storybook, create one story per pagination state rather than one story with a toggle — it makes visual regression testing far more reliable.
  • Envelope format works best for mobile API contracts because the client parses one JSON body instead of splitting logic between headers and body.
  • If your API uses a different field name like offset or pageIndex instead of page, generate JSON format and do a find-replace before committing to fixtures.
  • Pair this generator with a mock data generator for the data array inside envelope blocks so Storybook stories render fully populated list components.

FAQ

How do I mock API pagination data for frontend testing?

Generate several blocks at once by setting a higher count, then paste each block into a separate fixture file or Postman example. Each block has different page numbers, totals, and link values, so you can simulate navigating through pages without manually editing numbers. For component tests, assign one block per Storybook story or test case.

What pagination formats does this generator support?

Three formats: a plain JSON object with page, perPage, total, and totalPages fields; HTTP Link header strings following RFC 5988 (the format GitHub uses); and a full envelope structure that wraps a data array alongside meta and links objects, matching JSON:API and Laravel Paginator conventions.

Can I use the generated Link headers with React Query or SWR?

Yes. The Link header output follows RFC 5988 format with rel values of first, prev, next, and last. React Query doesn't parse headers automatically, but you can extract the next link from the response headers in your queryFn. SWR works the same way. Libraries like parse-link-header on npm handle the parsing for you.

What is envelope-style pagination and when should I use it?

Envelope format wraps the payload so the response body includes both data (an array of items) and pagination metadata (meta and links objects) in one structure. Use it when your API follows JSON:API, when mobile clients prefer a single-parse response, or when you're documenting an API that needs self-contained response examples.

How many pagination blocks should I generate for thorough testing?

Generate at least four to cover the main states: first page (no prev link), a middle page (both prev and next), last page (no next link), and a single-page result (no pagination links at all). Six to eight blocks help if you want intermediate pages or want to test components that display page-number ranges.

Can I use this output directly in an OpenAPI spec?

Yes. Copy a JSON block and paste it under the examples field of the relevant response schema in your OpenAPI YAML or JSON file. The values are realistic enough to satisfy tools like Swagger UI and Redoc, which display examples alongside the schema definition.

Do the generated totals and page numbers stay consistent across blocks?

Each block is generated independently with realistic but randomized values, so totals may differ between blocks. If you need a consistent dataset simulating pages from the same collection, generate a batch, pick one total value, and manually align the total field across the blocks before using them.

What is the difference between offset pagination and cursor pagination metadata?

Offset pagination uses page number and total count fields, which this generator covers well. Cursor pagination replaces page numbers with opaque cursor tokens pointing to the next or previous position in a dataset. This generator focuses on offset-style metadata; if you need cursor-based metadata, use the Link header output and substitute the URL query parameters with cursor values.