4 checks to run on every list screen before your API is ready
Most frontends are only ever tested against a fast, healthy backend. Then production happens: a request takes three seconds, a list has 450 rows instead of 12, a field is missing or full of stray spaces, and the spinner
Most frontends are only ever tested against a fast, healthy backend. Then production happens: a request takes three seconds, a list has 450 rows instead of 12, a field is missing or full of stray spaces, and the spinner you never saw turns into a blank screen.
You can test all of that before the real API exists, or without touching it, by pointing your client at a mock API. This post walks through four checks I run against every list screen, using plain fetch and a free hosted mock I built, Mock API Studio. Any mock that supports delays and pagination works the same way.
The sample endpoint
The mock comes with a public vms collection: 450 generated virtual machine records with host names, IPs, operating systems, owners and installed software.
curl -s "https://mockapi.toolkithub.in/api/v1/vms?limit=2&select=hostname,status,osType"
{
"vms": [
{ "vm_id": "vm-001", "hostname": " WEB-PROD-01 ", "status": "running", "osType": "Linux" },
{ "vm_id": "vm-002", "hostname": "app-win-07", "status": "stopped", "osType": "Windows" }
],
"total": 450, "skip": 0, "limit": 2
}
Notice " WEB-PROD-01 ". Some records are deliberately messy, which is the point.
Calling it from a browser app
The API doesn't send CORS headers, so a page on localhost can't call it directly. Route it through your dev server instead. With Vite:
// vite.config.js
export default {
server: {
proxy: {
'/api': { target: 'https://mockapi.toolkithub.in', changeOrigin: true },
},
},
};
Your app then calls /api/v1/vms, and Vite forwards the request. Node scripts, tests and cURL can use the full URL, because CORS only applies in browsers.
1. Does your loading state actually show?
Add delay (0–5000 ms) to slow a response down on purpose:
const url = '/api/v1/vms?limit=20&delay=3000'; // through the dev proxy
setLoading(true);
try {
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
setRows((await res.json()).vms);
} catch (err) {
setError(err.message);
} finally {
setLoading(false);
}
Things to look for with a 3 second delay:
- Does the spinner or skeleton appear, or does the old content just sit there?
- Can the user click "Refresh" five times and fire five requests? Disable the button or abort the previous request with an
AbortController. - If the user navigates away mid-request, do you set state on an unmounted component?
2. Does pagination reach the end exactly once?
Off-by-one pagination bugs are common and quiet. The API supports page-style paging and returns total_pages, plus an X-Total-Count header. This runs as-is in Node 18+ (node fetch-all.mjs):
async function fetchAll() {
const all = [];
let page = 1;
let totalPages = 1;
do {
const res = await fetch(
`https://mockapi.toolkithub.in/api/v1/vms?page=${page}&page_size=200&select=hostname`
);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
all.push(...data.vms);
totalPages = data.total_pages;
page++;
} while (page <= totalPages);
return all;
}
const rows = await fetchAll();
console.log(rows.length); // 450: three pages of 200, 200 and 50
Then check that the IDs are unique (new Set(rows.map(r => r.vm_id)).size === rows.length). If your table uses limit/skip instead, the same endpoint answers with { vms, total, skip, limit }.
3. Does your UI survive messy data?
Real data is never as clean as the fixtures in your tests. Search for a few cases and render them:
# Linux machines that are running
curl -s "https://mockapi.toolkithub.in/api/v1/vms?status=running&osType=Linux&limit=5"
# Full-text search across every field
curl -s "https://mockapi.toolkithub.in/api/v1/vms?q=ubuntu&limit=5"
Some records have padded or empty host names, invalid IP addresses and missing optional fields. Check that:
- you
trim()before displaying or comparing strings, - a missing field renders as "—" instead of
undefined, - sorting (
?sortBy=hostname&order=desc) still looks right with odd values.
4. Do errors reach the user?
The last check is failure. In the studio you can create your own collection, protect it with an API key or OAuth client, and use Test Controls to force 401, 429 (with Retry-After) or 503 responses. A minimal retry that respects Retry-After looks like this:
async function getWithRetry(url, options = {}, attempts = 3) {
for (let i = 0; i < attempts; i++) {
const res = await fetch(url, options);
if (res.status !== 429 && res.status !== 503) return res;
const wait = Number(res.headers.get('Retry-After') || 1);
await new Promise(r => setTimeout(r, wait * 1000));
}
throw new Error('Service unavailable, please try again later');
}
And for 401: refresh the token once, retry once, and if it fails again, send the user to sign in instead of looping.
Wrap-up
None of these checks need a backend team. Point your client at a mock, slow it down, page to the end, feed it ugly data and make it fail. If you want a head start, this request builder generates the cURL, fetch or Python call for any collection, filter and delay.
Disclosure: I built Mock API Studio as part of ToolkitHub, a set of free browser-based developer tools. Please don't store real personal data or secrets in any public mock.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.