Your first mock server
A mock server is a stand-in for a real API: it answers at the addresses you choose with the data you choose. In about ten minutes you will start one, add your own endpoint and call it three different ways.
What you need
- Mock Studio installed. See Install Mock Studio.
- Nothing else. A mock runs on your own computer and needs no internet.
Know the window
The first time Mock Studio opens, it creates a sample project called My First Mock API so there is something to explore.

- 1Rail — Endpoints, Live, Flows, Share and Project, then Import, Guide and Settings.
- 2Project — The project you are working in. One project is one mock API.
- 3Start server / Stop — Starts and stops the server. The address is shown just above.
- 4Endpoints — The addresses this mock answers at.
- 5Method and path — What request this endpoint answers.
- 6Send — Tries the endpoint without leaving the app.
- 7How it responds — One answer, rules, a sequence, or a random pick.
- 8Response — The status, headers and body to send back.
Part 1: start the server
With My First Mock API open, select Start server.
The card changes to Server running and shows an address such as
http://localhost:8080. The number after the colon is the port. Yours may differ; use the one you see.In the endpoint list, select Health check. It answers
GET /health.Select Send in the bar under the path. The response appears below: status
200and a small JSON body with the current time.
You now have an API running on your computer.
Part 2: call it from outside the app
The mock is a real HTTP server, so anything can call it.
From a browser. Select the Open in browser icon in the tester bar, or type the address yourself: http://localhost:8080/health.
From a terminal:
curl http://localhost:8080/healthFrom ApiWorkbench. Open a new request, enter http://localhost:8080/health and select Send.
Then open Live on the rail in Mock Studio. Every request you made is listed there with its time, method, path and status. Select one to see its headers and body.
Part 3: add your own endpoint
Go back to Endpoints and select New endpoint (the + beside the Endpoints heading).
Set the method to GET and the path to
/books/:id.The
:idpart is a path parameter: it matches anything in that position, so the endpoint answers/books/1,/books/2and/books/abc.Give it the endpoint name
Get book.Leave Single response selected. In the response, keep the status at 200 and the body type at JSON.
Replace the body with:
json{ "id": "{{params.id}}", "title": "Book number {{params.id}}", "author": "{{faker.name}}", "fetchedAt": "{{now}}" }Select Send in the tester bar, or open
http://localhost:8080/books/7in your browser.
The answer has 7 where you wrote {{params.id}}, a made-up name where you wrote {{faker.name}}, and the current time. Those double-brace tokens are templates: Mock Studio fills them in on every request. The Insert variable button lists the common ones, and Dynamic templating lists them all.
Part 4: make it say no
Real APIs do not always say yes. Make this one return 404 for one book.
In Get book, choose Conditional rules.
Select Add response. Label the new response
Not found, set the status to 404, and use this body:json{ "error": "not_found" }On that response, select Add condition and set it to Path param
idequals0.Make sure the
Not foundresponse comes before the plain one. A response with no conditions is the fallback.Call
/books/0, then/books/5.
/books/0 now answers 404 and every other id answers 200. You have built an API that behaves differently depending on the request, which is what you need in order to test how an app copes with errors.
Check yourself
Question 1 of 6
The server card shows http://localhost:8080. What is 8080?
What you learned
- A mock server answers real HTTP requests with the responses you design.
- Start server runs it; Live shows every request it receives.
- Path parameters such as
:idmatch many URLs; templates such as{{params.id}}put request data into the response. - Conditional rules choose a response from the request.
Next steps
- Response strategies: rules, sequences and random answers
- Latency and faults: slow and broken answers on purpose
- Todo API lab: test a ready-made mock from ApiWorkbench
- Share on LAN or the internet: call the mock from a phone