Dev
Mock HTTP Status Response Generator
Testing how your application responds to HTTP errors requires controlled, predictable responses — a 503 at exactly the wrong moment in a retry loop, a 401 when a token has expired. A mock HTTP status response generator produces complete HTTP responses — status line, headers, and a realistic JSON body — for any status group, so you can build error-handling logic without waiting for a live server to fail. Two inputs control the output. Status Group filters which codes appear: 2xx (200, 201, 202, 204, 206), 3xx (301, 302, 304, 307, 308), 4xx (400, 401, 403, 404, 409, 422, 429), 5xx (500, 502, 503, 504), or any. Count sets how many responses to generate (1–20). Each response includes the HTTP status line, Content-Type, X-Request-ID, and Cache-Control headers. Success bodies (2xx) include a data object. Error bodies (4xx/5xx) include an error object with code, message, and requestId.
How to use
- Choose your options above
- Click Generate
- Copy your result
Detailed instructions
- Select a Status Group from the dropdown — choose 'Any' for a mixed set or a specific group like '4xx Client Error' to focus your test batch.
- Set the count field to how many mock responses you need, typically three to five for a test suite or one to two for documentation.
- Click Generate to produce the mock HTTP responses, each showing the status line, headers, and JSON body.
- Copy individual responses and paste the JSON body into your test fixture, mock server, or API documentation as needed.
- Regenerate as many times as needed to get varied status codes within the same group for broader test coverage.
Use Cases
- •Populating Postman mock servers with realistic 4xx and 5xx response bodies
- •Writing Jest or Vitest unit tests that assert correct handling of 401 Unauthorized
- •Seeding Storybook stories with varied HTTP error states for UI component testing
- •Generating API documentation examples covering both 2xx success and 4xx failure paths
- •Testing exponential backoff and circuit breaker logic using batches of 5xx responses
Tips
- →When testing retry logic, generate five or more 5xx responses at once to get varied codes like 500, 502, 503, and 504 in one batch.
- →Pair a generated 401 body with a 200 body to build realistic login-flow tests that cover both authenticated and unauthenticated states.
- →For API docs, always include at least one 4xx and one 5xx example alongside your 2xx success response — readers need to see failure modes.
- →The X-Request-ID in the headers is a useful field to reference in your error handling UI — show it in error messages so users can report it.
- →When using responses in Storybook, create one story per status group so each UI error state has a dedicated, reproducible example.
- →If your API uses 422 Unprocessable Entity for validation errors, filter to 4xx and look for 422 responses — their bodies typically include a field-level errors array you can adapt.
FAQ
how do I use mock HTTP responses in Jest or Vitest tests
Copy the generated JSON body and use it as the return value in a jest.fn() or vi.fn() mock for your fetch or Axios calls. Set the matching status code on the mock response object — for example, { status: 401, json: () => body }. This lets you assert correct error-handling behavior without a real server or network request.
are the generated JSON response bodies realistic enough for real test suites
Yes. Success responses (2xx) include a data object, a status flag, and a requestId. Error responses (4xx/5xx) include an error code, a human-readable message, and the same requestId echoed from the header — matching conventions used by Express, Django REST Framework, and Spring Boot.
what is the difference between a 502 and 503 in the generated output
A 502 Bad Gateway body signals an upstream server returned an invalid response — your server is up but something behind it failed. A 503 Service Unavailable body indicates the server itself is temporarily down or overloaded. Both appear in the 5xx group, and the generator produces distinct JSON bodies for each.
can I filter to generate only 4xx or only 5xx responses
Yes. Set Status Group to 4xx to get only client error responses (400, 401, 403, 404, 405, 409, 422, 429), or 5xx to get only server error responses (500, 501, 502, 503, 504). Regenerate multiple times within a group to get different codes — the pool is randomly sampled each run.
You might also like
Popular tools from other categories that share themes with this one.
Try these next
More free tools from other corners of the catalog, picked by shared themes.