Create and edit a mock
Before you begin
- Role
- Editor or higher.
- You need
- A project
A mock says which requests it answers and what it answers with. This page creates one that answers GET /orders with a list of orders, then changes and deletes it.
Choose Path and query to compare the whole path and query string, Path only to ignore the query string, or Regex for a path pattern. Enter any status code from 100 to 599 under Status code.
Create a mock
Section titled “Create a mock”-
Open the project, and select its Mocks tab.
-
Select New mock. In a project with no mocks, the button reads Create the first mock.
-
Enter a Name, such as
List orders. No two mocks in a project can share a name. -
Leave Status at Active to have the mock answer as soon as you save it, or choose Inactive to prepare it without affecting callers.
-
Under Which requests it answers, enter
/ordersas the path. The method is alreadyGET. -
Under What it answers, replace
{}in the Response body with the body to send:{ "orders": [{ "id": 8821, "status": "paid" }] } -
Select Save mock, which returns to the Mocks tab. To save and keep editing, press Ctrl+S (⌘+S on a Mac) instead: the new mock opens at its own address.
A new mock starts as GET / answering OK (200) with a Content-Type: application/json header and the body {}, so you change only what differs. It has one response, which is its default. Match requests and Build the response cover every field, and Choose the response that answers covers a mock with several. To send the mock a request before you save it, see Test a mock before saving.
Edit a mock
Section titled “Edit a mock”-
On the project’s Mocks tab, select the mock’s name.
-
Change what it matches or what it answers.
-
Select Save mock, or press Ctrl+S (⌘+S on a Mac) to save and stay in the editor.
Delete a mock
Section titled “Delete a mock”-
On the project’s Mocks tab, select Details on the mock’s row.
-
Select Delete at the end of the details.
-
Select Delete mock in the dialog Delete this mock?.
To delete several mocks at once, tick the checkbox of each one on the Mocks tab, select Delete above the list, and confirm in the dialog, which names how many, such as Delete 3 mocks.
Changes made elsewhere
Section titled “Changes made elsewhere”The Mocks tab and the editor follow changes to the project’s mocks made anywhere else: in another tab, by a teammate, by an AI assistant, through the configuration document or by an import. A tag above the list says what the list is doing:
| Tag | What it means |
|---|---|
| Live | Nothing is ticked, open or being changed. A change appears by itself about a second after it is saved, on the page, filters and order you chose. Request counts and the last call follow traffic at most every 10 seconds. |
| Paused | A mock is ticked or its details are open, a dialog is open, or an action is running; the words beside the tag say which, such as “while a row is open”. The rows stay as they are, and Mocks changed elsewhere. appears when something changed. Show changes reads the list again and clears the ticks. |
| Reconnecting… | The connection dropped. The list reconnects by itself and reads the list again once it is back. |
| No tag | Live updates are not available here. The list changes when you change a filter, the order or the page, or reload the browser page. |
When changes elsewhere leave the page you are on empty, the list moves to the last page there is. Live updates stop while the browser tab is hidden, and start again with a fresh read when you return to it.
While you edit a mock:
- With no edits of your own, the editor shows the mock as it is saved now.
- With unsaved edits, a change elsewhere to what the mock matches or answers, its name, status, tags, scenario or contract link shows This mock changed elsewhere. and switches Save mock off, so your edits cannot overwrite it. Copy what you need, then select Discard my edits and reload.
- If the mock is deleted elsewhere, This mock was deleted elsewhere. appears and Save mock is off. Your edits stay on the page until you leave it, and Back to mocks returns to the list.
- A change that leaves the mock as you loaded it, such as more requests answered, does not interrupt you.
Result
Section titled “Result”After a save, MockHub shows Mock created or Mock saved and returns to the Mocks tab, where the mock’s row shows its name over its method and path, its status and its response code. An active mock answers from the next request on. Call it at the address shown under the project’s name:
curl https://orders-api.mockhub.dev/orders{ "orders": [{ "id": 8821, "status": "paid" }] }After a deletion, MockHub shows Mock deleted, or how many went, such as 3 mocks deleted. The mock’s version history goes with it, while the requests it already answered stay in the project’s request logs; to remove those too, delete everything the mock answered first. From then on, the requests it used to answer are unmatched requests, unless another mock answers them.
Limits
Section titled “Limits”- The plan limits how many Active mocks a project and a workspace can have. Inactive mocks do not count. At the limit, saving an active mock is refused with a message naming the limit; see Plans, quotas and limits.
- A mock cannot be deleted while a webhook is sent when it answers. Detach the trigger first; see Fire a webhook when a mock is served.
- When one of several ticked mocks has such a webhook, none of them is deleted, the message names the webhook and the mock, and the selection stays so you can narrow it.
- More than one mock can match the same request, and MockHub does not let you order them. See Request matching.
- Live updates say only that something changed. Several changes within a second appear together, and the editor cannot merge your edits with a change made elsewhere. Version history, the project’s settings and the OpenAPI pages show changes made elsewhere when you open them again.
- A Viewer can open a mock and read it, with “Changing this mock needs the Editor role.”, but cannot save it.
- A mock holds up to 50 responses. A default changed elsewhere, such as by a teammate or a CLI command, is a change to the mock like any other: it shows This mock changed elsewhere. and switches Save mock off while you have unsaved edits.