Writing mock responses by hand takes time, and they drift away from what the real API returns. Recording is faster: Mockhop sits between your app and the real API, keeps a copy of each request and response, and you turn the ones you need into mocks.
When it helps
- The real API is slow, or it charges per call.
- Its test data keeps changing, so your tests break for reasons that have nothing to do with your code.
- It's only available at certain times, or your sandbox account is rate limited.
- You want realistic responses to start from, then adjust them.
How it works
- Turn on proxy mode for a project and enter the real API's address as the target, for example
https://api.example.com. - Point your app at your mock URL. Requests that no endpoint answers go to the target. For example,
…/payments/v1/ratesgoes tohttps://api.example.com/v1/rates. Your app gets the real response. - Mockhop stores each request and response as a recording, with headers and bodies.
- Turn recordings into endpoints. In Proxy recordings, select Convert to mock on the ones you need. From then on, Mockhop answers those requests itself, because an endpoint that matches comes before the proxy.
Endpoints you've already created keep answering, and everything else still goes to the real API. You can move from "all real" to "all mocked" one endpoint at a time. Step by step: Record a real API as mocks.
After converting
A converted endpoint is a normal endpoint. You can, for example:
- add
{{ … }}template values to the recorded body - add a second response for an error case
- add a delay
A single endpoint as a proxy
An endpoint can also forward its own calls to a full upstream URL. Mockhop records those calls as well.
Already have a capture?
If you recorded traffic in your browser's developer tools, import the HAR file instead. Mockhop creates endpoints from it; see Import.
Good to know
- Cloud vs. self-hosted: in the cloud version, the target must be a public address; private and internal networks are blocked. A self-hosted installation can record APIs in your internal network.
- Sensitive headers: headers such as
Authorization, cookies and tokens are masked in recordings and left out when a recording becomes a mock. - Only record what you're allowed to: record APIs you're allowed to use, and prefer test accounts to production credentials. Recordings are kept for 90 days.
- Request counting: forwarded requests count toward your monthly requests.
- Plans: the proxy and proxy recording are part of the Pro, Team and Business plans. They aren't available on the Free plan.
Plans and limits: pricing.