Turn captures into mocks
Before you begin
- Plan
- Included in Pro and Team. How plans and limits work
- Role
- Editor or higher to promote captures and Viewer or higher to compare a capture with its mock.
- You need
- Captures from a project that records a real API
Promoting a capture creates a mock that answers the way the real API did, so you can record an API once and then work without it. To record in the first place, see Record traffic from a real API.
For requests recorded outside MockHub, in a browser’s HAR export, a Postman collection or curl output, see Import mocks from a HAR, Postman or curl.
-
Open the project’s Captures tab.
-
Choose the period to review: Last 24 hours, Last 7 days or Last 30 days.
-
Check each endpoint you want as a mock. Only rows marked Not mocked have a box; Select every endpoint that has no mock yet, in the column heading, checks them all.
-
To keep replayed answers from looking stale, check Keep timestamps and ids fresh. It is offered only when the project has Response templating on.
-
Select Create mocks.
Result
Section titled “Result”A message says how many mocks were made, such as “2 mocks created.”, and lists any endpoint it skipped with the reason:
| Reason | Why |
|---|---|
| This endpoint already has a mock. | A mock covers it, perhaps made from another tab meanwhile |
| A mock answered that request, so there is nothing recorded to promote. | The request was not forwarded to the upstream |
| That capture is no longer in this project. | It was deleted, or removed after the plan’s retention period |
| Reason | Why |
|---|---|
| The response is binary, such as an image, and a mock body is text. | The upstream answered with bytes that are not text |
The promoted rows now show Mocked, linked to their new mocks, and the mocks appear on the project’s Mocks tab.
A Mocks tab open elsewhere shows the new mocks by itself while it reads Live. While the Captures tab reads Live, a mock created or deleted elsewhere, such as from another tab, marks its endpoint Mocked or Not mocked there too, and a checked endpoint that a mock now covers is unchecked.
What a promoted mock contains
Section titled “What a promoted mock contains”- A row whose path has an identifier in it, such as
/orders/{id}, becomes one mock with a Path with parameters,/orders/{id}, named after the row, such asGET /orders/{id}, so it answers every order. Any other row becomes a mock for its path, such asGET /orders. Either way the query string does not matter, and there are no header, query or body rules. - It is Active at once, with
-2,-3and so on added to its name when the name is taken. - It answers with the recorded status,
Content-Typeand body, redacted fields included; see Captures. Other response headers are not copied. - A JSON body recorded on one line is laid out over several, indented by two spaces, so it reads in the mock editor. Only the spacing changes: every value stays as recorded.
- With Keep timestamps and ids fresh, JSON values that are UUIDs or ISO 8601 timestamps become templates that produce a new UUID or the current time on every answer.
In an XML body, Keep timestamps and ids fresh does the same to element text and attribute values, keeping the body’s layout.
A promoted mock’s Response templating is Serve as written, so it answers with the recorded body exactly, {{…}} included: the upstream wrote that text, and a template in it could otherwise read the project’s data. A mock whose values Keep timestamps and ids fresh rewrote is set to Follow the project instead. A capture whose body or headers already hold {{ is promoted without rewriting, as written.
A promoted mock is tagged with the host of the upstream that answered the capture, such as api.example.com, so the Any tag filter finds what one upstream recorded, even after you point the project at another one. A promoted inbox post is tagged inbox. A capture recorded before MockHub kept which upstream answered is tagged with the upstream the project names when you promote.
Promoted mocks count against the plan’s mock limits like any other.
Compare a mocked endpoint with the upstream
Section titled “Compare a mocked endpoint with the upstream”On a Mocked row, select Compare. Compared with the mock says either “Nothing differs — the mock still matches the upstream.” or “The mock no longer matches what the upstream answered.”, and lists what changed in the status, content type and top-level JSON keys. Open the mock opens it to update, and Update with AI on the row asks the assistant to change it to what was recorded. The comparison is shallow; see Captures.
Two XML bodies are compared too. Their keys are the root element’s attributes, shown as @id, and its child elements, ignoring indentation and comments. A SOAP response is compared by the message inside its Body, whatever prefixes the two use.
Parameterise with AI
Section titled “Parameterise with AI”A promoted mock replays one recorded answer. When the answers vary with the request, such as an order whose body repeats the id from its path, ask the assistant instead:
- For endpoints without a mock, tick up to 10 and select Parameterise selected with AI beside Create mocks. It proposes one mock for each.
- For a Mocked endpoint, select Update with AI on its row. It proposes changing the covering mock rather than adding another.
For each endpoint, the assistant reads up to three of its newest captures from the last 30 days, with what the upstream answered, and makes one mock answer every request of it. It keeps the shape of the recorded answers, and when the project has Response templating on, it takes what varies from the request; otherwise it serves one recorded answer as written.
When the project has Response templating on, two boxes above the list change what the assistant is asked:
- Keep timestamps and ids fresh asks for the current time in each timestamp and a new random id wherever the request does not name one.
- Fill with random data asks it to replace the recorded values with random data of the same kind, such as names, prices and text, keeping those the request supplies. Use it for test data rather than a faithful copy. Only the assistant can do this, so Create mocks is off while it is ticked, and selecting it says “Random data needs the assistant”.
Each adds a sentence to the instruction, which you can read and change before you select Send.
Prefer promotion for a faithful copy of what was recorded: it is immediate and its mock is Active at once. The assistant’s proposal is reviewed first, its new mock is Inactive until you activate it, and each question uses the plan’s assistant allowance. It needs the Editor role and a plan with the assistant.
Promote one request, or an inbox post
Section titled “Promote one request, or an inbox post”A single logged request can become a mock on any plan, including a post to the project’s webhook inbox:
-
Open the project’s Request logs tab.
-
Select Filters, open Any outcome and choose Forwarded to your upstream or Webhook inbox.
-
Select Create a mock from this request on the row.
The new mock opens in the editor, with a JSON body laid out as a promoted capture’s is.
A request that no mock answered creates an Inactive draft. Set its response, test it with Try it, and activate it when ready; it does not immediately serve the unmatched request’s 404.
A message then says Draft mock created, and the editor says This mock is inactive. above the form. Save and activate there saves your changes and activates the mock in one step.
A mock made from an inbox post keeps the post’s path, such as /__inbox/payments. MockHub answers every path under /__inbox itself, before any mock, so that mock never answers until you change its path in the editor, such as to /payments.
Limits
Section titled “Limits”A capture whose body was cut off at the plan’s size limit cannot be promoted: “This capture was truncated and cannot be promoted as a faithful replay. Create a mock explicitly with the complete body.” Create that mock by hand.
A request whose method no mock can match, such as HEAD, cannot be promoted.
Nor can a capture whose response is binary, such as an image, because a mock body is text: “This response body is binary, and a mock body is text. Create a mock explicitly with the body it should serve.” Create mocks skips it with a reason.
Create mocks skips incomplete captures and unsupported methods, with a reason for each row, and creates the usable ones. An unexpected refusal rolls back the whole batch, so it does not leave earlier mocks behind.
Mocked means a mock would answer the newest capture in the row, whatever kind of path it uses. A mock for /orders/8821 does not make /orders/{id} Mocked, because it would not answer /orders/42.
Promoting one request keeps that request’s own path, such as /orders/8821. Create mock in insights uses the row’s Path with parameters, as Create mocks here does.
A promoted mock uses Path only matching. Saving it in the editor preserves that choice; choose Path and query if the query string should participate.
The screen lists up to 50 endpoints for the period, the most captured first. Nothing compares captures with their mocks automatically. Compare is the check, and you run it.