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.
Two parameters, that's the whole contract
Every collection endpoint accepts page and limit. No SDK, no config — they are plain query-string parameters.
GET /m/you/shop/products?page=2&limit=10Host: mocksmith.lioncore.devpage— 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.
{ "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:
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
Describe
« A shop with products: id, name, price, a category. »
Set a count
Tell MockSmith to forge 140 products. Pagination is automatic — nothing to configure.
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 mockRead next
Comparison
A hosted json-server alternative (no install, real data)
json-server is great locally. When you need a shared URL, realistic data and relations without maintaining a db.json, a hosted mock is the better fit.
5 minRecipe · Auth
Add Bearer token auth to your mock API
Lock your mock endpoints behind an Authorization: Bearer header — one key flips every route from public to protected, with clean 401s to test against.
4 min