Testing error states and slow responses with mock servers
The happy path is easy to test because the real API gives it to you every time. Everything else is hard: the 404 for a deleted order, the 422 with three validation errors, the 503 when a dependency is down, the response that takes six seconds. Those are exactly the states where frontends break and where users see a blank screen.
A mock server that can return any of them on demand makes them easy to build and to test.
Save one example per state
On a request in your collection, save an example for each response you want to reproduce. Most error states are easy to trigger against a dev or staging API: send the request, then click Save as example.
| State | How to trigger it once | Status |
|---|---|---|
| Normal | Send as usual | 200 |
| Not found | Use an ID that doesn't exist | 404 |
| Validation failed | Send an invalid body | 422 |
| Unauthorized | Send without a token | 401 |
States you can't easily trigger, like a 503 from a dependency or a 429 rate limit, can come from your API spec: OpenAPI response examples (and Postman saved responses) become saved examples when you import them.
Pick the response per call
Once the collection has a mock server (Mocks → Create mock server), a header chooses the example:
# by status code
curl https://mock.requestarium.com/m_8f3k2x9q1z/orders/42 -H "x-mock-response-code: 404"
# by example name, when two examples share a status
curl https://mock.requestarium.com/m_8f3k2x9q1z/orders/42 -H "x-mock-response-name: <example name>"Without a header: the default example, otherwise the first 2xx, otherwise the first one.
Use it in frontend tests
Because the choice is a request header, your component or end-to-end tests can ask for a state directly. For example, in a test helper:
async function getOrder(id, mockStatus) {
const headers = mockStatus ? { 'x-mock-response-code': String(mockStatus) } : {};
return fetch(`${API_URL}/orders/${id}`, { headers });
}
// in a test
await getOrder('42', 503);
// assert the page shows the "payments are temporarily unavailable" bannerNo local mock definitions to maintain, and the examples are the same ones the whole team sees in the collection.
Slow responses
Loading spinners, skeleton screens, timeouts and retry logic are only testable when the API is slow. On Pro and Team, a mock server can add a delay of up to 10 seconds before every answer. Create a second mock server with a delay for "slow network" testing, and keep the first one fast.
Keep CI away from third-party APIs
The same trick protects your test suite from things you don't control. Instead of calling a real payment provider or a rate-limited partner API in CI, point those calls at a mock with saved examples of the provider's responses, including its error responses. Tests get faster and stop failing when the partner has a bad day.
Private mocks
A mock server URL is unguessable, but anyone who has it can call it. On Pro and Team you can make a mock private: calls must send its key in x-api-key. Use that for mocks that hold realistic customer-like data.
What a mock can't tell you
Limits
Mock servers answer up to 60 calls a minute on Free, 300 on Pro and 1,000 on Team, with monthly quotas of 10,000, 500,000 and 5,000,000 calls. Full details in the mock servers docs.