Recipe · Pagination

How to mock a paginated REST API (no backend)

Your list view needs pages, your designer needs 140 rows, and the backend endpoint does not exist yet. Here is how to serve a paginated collection in two minutes, with data that stays identical across reloads.

Updated June 7, 20264 min

Two parameters, that's the whole contract

Every collection endpoint accepts page and limit. No SDK, no config — they are plain query-string parameters.

request
GET /m/you/shop/products?page=2&limit=10Host: mocksmith.lioncore.dev
  • page — 1-based. Defaults to 1, capped at 10 000.
  • limit — items per page. Defaults to 20, capped at 100.
  • Out-of-range or garbage values fall back to the defaults instead of erroring.

A response envelope you can paginate on

The collection comes wrapped with everything a pager needs — the slice of data, plus the counts to build page controls.

response
{  "data": [    { "id": "8f3a…", "name": "Forged Hammer", "price": 24.9 }  ],  "page": 2,  "limit": 10,  "total": 137,  "totalPages": 14}

Same data, every reload

Records are generated once from a seed and served in a stable order (oldest first). Page 2 today is page 2 tomorrow — your screenshots and tests don't drift.

Wire an infinite scroll (or a pager)

totalPages is all you need to know when to stop. Here, fetching an entire collection page by page:

client
const base = "https://mocksmith.lioncore.dev/m/you/shop"; async function fetchAll() {  const all = [];  let page = 1;  while (true) {    const res = await fetch(`${base}/products?page=${page}&limit=100`);    const { data, totalPages } = await res.json();    all.push(...data);    if (page >= totalPages) break;    page++;  }  return all;}

Get there in three moves

01

Describe

« A shop with products: id, name, price, a category. »

02

Set a count

Tell MockSmith to forge 140 products. Pagination is automatic — nothing to configure.

03

Paginate

Hit the URL with ?page= and ?limit=. Your list view is live.

Frequently asked

Can I filter or sort the collection from the query string?

Server-side filtering and sorting are not built in — the collection returns in a stable order and you slice it with page/limit. For a fixed subset, model it as its own resource (e.g. featured-products).

What if I ask for a page past the end?

You get a valid response with an empty data array and the real total/totalPages, so your UI can stop cleanly.

Do POST/DELETE change the pagination?

Yes — created records persist and appear at the end of the collection, deleted ones disappear. total updates live. A scheduled reset (Pro) can restore the original dataset.

Stop waiting on the backend.

Forge your own mock API in two minutes. Free, up to two projects, no credit card.

Forge a free mock

Read next