Guides
Mock a backend
Answer a captured request with your own response using Map Local, cover error and empty states, and replay a whole API offline with Mock Sets or an API-client mock server.
The backend isn’t ready, or you need to see how the app handles an error, an empty list, or a slow 500. This guide answers a captured request with a response you control using Map Local, then shows two ways to mock a whole API: Mock Sets (record real traffic, replay it offline) and an API-client mock server (serve saved examples from a collection).
What you need
Section titled “What you need”| Cloak Proxy capturing the app, with HTTPS decrypted | See Debug a mobile app or SSL Proxying |
| At least one captured request to the endpoint you want to mock | Map Local and Mock Sets are built from real traffic |
Mock one endpoint with Map Local
Section titled “Mock one endpoint with Map Local”Map Local answers matching requests with a response you write. The real server is never contacted.
-
Capture the request once so you have a real response to start from. Right-click it and choose Tools → Map Local….
Cloak Proxy copies the captured status, the important headers (Content-Type, caching, cookies, CORS), and the body into a new rule, and turns the tool on.
A Map Local rule prefilled from a captured response.
- Tool on/off
- Matcher: method and URL
- Inline, File or Directory
- Status code
- Valid JSON check, Format and Minify
-
Choose where the response comes from:
Source What it does Inline A status, headers and body you type here File A file on disk. Content-Type is guessed from the extension if you don’t set one Directory A folder of files picked by request path. Missing files fall through to the real server -
Edit the response. For Inline, set the Status code, adjust the Headers, and edit the Body (JSON gets a Valid JSON check, Format and Minify).
-
Repeat the request from the app, or right-click and choose Repeat. The response now comes from your rule, tagged Map Local in the traffic list.
Cover error and empty states
Section titled “Cover error and empty states”Map Local is the quickest way to see how the app handles responses it rarely gets. Duplicate the rule (right-click → Duplicate) and change the copy:
| To simulate | Set |
|---|---|
| A server error | Status code 500, body {"error":"Simulated failure"} |
| Rate limiting | Status code 429, header Retry-After: 30 |
| An empty list | Status 200, body [] or {"items":[]} |
| Not found | Status code 404 |
| Unauthorized | Status code 401 |
Enable one rule at a time with its checkbox to flip between states. Rules run top to bottom; the first match wins.
Replay a whole API offline with Mock Sets
Section titled “Replay a whole API offline with Mock Sets”A Mock Set is a snapshot of an API’s responses. While it’s on, matching requests are answered from the snapshot with no network, so you can demo, test or debug the app exactly as it behaved when recorded.
-
Capture the flows you want to replay by using the app normally.
-
Make a set. Select the requests and choose Tools → Mock Sets → From Selected Requests, or right-click a domain in the sidebar and choose Mock host Offline to snapshot every captured response from that host.
A Mock Set. Each recorded response is editable.
- Tool on/off
- Offline: answer unrecorded requests with 404
- Ignore query strings when matching
- Recorded responses; select one to edit it
-
Set how it matches:
Option Effect Offline: answer unrecorded requests to these hosts with 404 Nothing reaches the real host, so you test exactly what was recorded. Off: unrecorded requests go to the server Ignore query strings when matching /users?page=2is answered with a recording of/users?page=1 -
Select any response in the table to edit its status, headers or body, the same as Map Local. The most recent recording of a request wins when it was captured more than once.
-
Turn the set on with the switch. Disconnect from the network and the app keeps working from the snapshot.
The API-client alternative: a mock server
Section titled “The API-client alternative: a mock server”When your mocks live as saved examples in an API-client collection rather than captured traffic, run a mock server. It serves the collection’s examples on localhost, so you can point a dev build at it.
-
In the API Client (
<kbd>⇧</kbd> <kbd>⌘</kbd> <kbd>O</kbd>), save some responses as examples (Save as Example on a response), or import an OpenAPI spec that has examples. -
Open Mocks, pick the collection, and click Start Mock Server.
A mock server serving a collection's examples on localhost, with routes and a call log.
- Mocks section
- Port, delay, CORS, and the localhost URL
- Routes from the saved examples
- Live calls
-
Point your app at the printed
http://localhost:PORT. Routes match by method and path (:paramsmatch anything). Sendx-mock-response-nameorx-mock-response-codeto pick a specific example.
Clean up
Section titled “Clean up”-
Turn off Map Local, Mock Sets (and Scripting if used) in the Tools window so real traffic flows again.
-
In the API Client’s Mocks view, click Stop on any running mock server.
-
If you pointed a dev build at
localhost:PORT, point it back at the real backend.