Frontend work often waits for an API that's still being built. With a mock API, you agree on the shape of the responses, put them behind a real URL and build against that. When the backend is ready, you switch the base URL.
Set it up
Describe the API. If the backend team already has an OpenAPI file or a Postman collection, import it and Mockhop creates the endpoints. Otherwise, create them by hand (quickstart).
Point your app at the mock URL. Keep the address in an environment variable:
API_BASE=https://acme.mockhop.cloudfetch(`${API_BASE}/payments/orders`)Share it. Everyone on the team, preview deployments and testers call the same URL and see the same responses.
Realistic data instead of "foo" and "bar"
Templates fill responses with generated values on every call: names, addresses, companies, card numbers and more, in English, German, Turkish and French. Responses can also repeat values from the request, so a form you submit comes back the way a real API would return it.
Every state your UI has to handle
- Loading: add a delay to a response, or a random delay between a minimum and a maximum, to see your spinners and skeletons.
- Errors: return a 500 for some calls, a 404 for a missing item, or a 422 with validation messages.
- Empty and full lists: use matching rules on a query parameter, for example
?page=2or?status=archived, to return different responses from the same endpoint.
See Simulate API errors for the details.
Calling mocks from the browser
Mocks answer CORS preflight requests from any origin and allow the request headers your app asks for, so an app running on localhost or a preview URL can call them directly, custom headers included.
If your app sends cookies or other credentials, set Access-Control-Allow-Origin to your app's origin and Access-Control-Allow-Credentials: true in the response headers. Credentials work on paid plans; on the Free plan, responses use *.
Switching to the real backend
When the real API is ready, change API_BASE. If only part of it is ready, turn on proxy mode for the project: requests that no endpoint answers go to the real backend, and the endpoints you still mock keep answering. You can then remove them one by one. Proxy mode is included from the Pro plan.
Good to know
- REST and GraphQL mocks are part of every plan, including Free.
- Your mocks become reachable once you've confirmed your email address.
Plans and limits: pricing.