API mock server: build a mobile app before the backend is ready
The design is approved, and the endpoints are three weeks away. The mobile team waits, or builds screens on stubs in the code and rewrites them later. A mock server in Microkoi Bench turns the API agreement into a working server on day one. The app makes real network calls, and Android and iOS get the same responses.
Why stubs in the code let you down
A stub lives inside the app: JSON in the resources or a class with ready-made objects. Each platform has its own. A couple of weeks later, Android and iOS expect different fields, and neither stub matches what the backend ends up building.
Worse, a stub bypasses the network layer. Response parsing, the loading state, pagination and errors go untested. All of it surfaces on the day the app first talks to the real server.
Start with the API agreement
Start with what the screens need. An hour with a backend developer gives you a list of endpoints, fields and errors. For example, for the workouts section of a fitness app:
| Endpoint | What it returns |
|---|---|
GET /api/ | This week’s workouts, page by page |
GET /api/ | A workout with its exercises |
POST /api/ | Workout summary |
POST /api/ → 409 | Workout already finished |
An asterisk in the path matches one segment: the endpoint answers for any workout ID.
The agreement becomes a server
- Open the “Mock servers” section and click “Empty mock server”. The server takes the first free port, starting at 9091.
- For each endpoint, click “+” above the list and set the name, method, path, status code and response body.
- In “Description”, write down what the endpoint promises: required fields, allowed values, what doesn’t work.
- Save the endpoint and start the server with the “Running” switch.
{
"items": [
{
"id": "w-101",
"title": "Back and shoulders",
"durationMin": 45,
"cover": "{{baseUrl}}/media/workouts/w-101.svg",
"status": "planned"
}
],
"page": 1,
"total": 18,
"next": "{{baseUrl}}/api/v1/workouts?page=2"
}The server replaces {{baseUrl}} with the address it was called at. The next-page link and the covers point to the mock server itself, from the simulator, the emulator and the phone alike. The covers come from a GET endpoint with a file as its body.
Set the list’s “Delay” field to 300 ms. The loading state shows up on screen from the first run, not after a tester complains.
Errors are part of the agreement
The 409 response is a separate endpoint with the same method and path as “Finish workout”. Put it in the “Errors” folder and leave it disabled. To test error handling, disable the main endpoint and enable this one. The switch takes effect right away, no server restart needed.
One server for Android and iOS
A mock server is files in the workspace folder: each endpoint in one file, its body next to it in another.
mock-servers/
└── Fitness API/
├── server.json
├── Workouts/
│ ├── Workout list.endpoint.json
│ ├── Workout list.body.json
│ ├── Workout.endpoint.json
│ ├── Workout.body.json
│ ├── Finish workout.endpoint.json
│ └── Finish workout.body.json
└── Errors/
├── Workout already finished.endpoint.json
└── Workout already finished.body.jsonPut the workspace in git, and a second developer gets the same server with git. Bench picks up file changes on its own. A change to the agreement becomes an ordinary commit: the changed field shows up in the body diff and gets discussed in code review. There’s nowhere for the platforms to drift apart.
Bench doesn’t trust a workspace from a repository at first: its mock servers don’t start on their own until you click “Trust workspace”. You can always start a server by hand with the “Running” switch.
Connect the app
In the debug build, point the API base URL at the mock server. One port accepts both HTTP and HTTPS. For the emulator and the phone, turn on “Network access” next to the server addresses.
iOS Simulator http://127.0.0.1:9091
Android emulator http://10.0.2.2:9091
Phone on Wi-Fi http://192.168.1.15:9091The request log shows what’s missing
A screen needed an endpoint that isn’t in the agreement. The “Request log” tab shows that request marked “no endpoint”. The “Create endpoint” button next to it opens a draft with the same method and path, so all that’s left is the body and the description.
Give the backend an API description, not a retelling
The “Export API to note” button in the server header builds a note: the base URL, a table of contents, and every endpoint with its description, status code, headers and a sample response. Disabled endpoints go into a separate section as error variants. The note lives in “Notes” and goes to git along with the server.
What a mock server doesn’t do
- It doesn’t keep state. “Finish workout” always returns the same summary, and the status in the list doesn’t change. The real server will change it, and the screen has to handle that.
- It ignores page parameters until you add variants with conditions on page.
- It doesn’t check headers. It won’t reject an expired token: a 401 response is a separate endpoint you enable.
- It responds with the delay you set. A real server on a mobile network can be slower and can fail: 3G speed, errors and dropped connections come from the mock server’s chaos.
Switching to the real server
Point the debug build at the test environment and route the app through the Bench proxy. The recorded traffic shows where the API drifted from the agreement: a different field name, an empty string instead of null, a different error code. You see these mismatches in the very first requests, not in a tester’s report.
Keep the mock server in the repository. It comes in handy for demos, for automated tests and for days when the test environment is down.
Starting a feature before the backend? Try this approach in the beta and write to beta@microkoi.com about what worked and what was missing. We read every email.