Skip to content

Record traffic from a real API

Before you begin

Plan
Included in Pro and Team. How plans and limits work
Role
Admin or higher to set up recording and Viewer or higher to review what was recorded.
You need
  • A real API that can be reached from the public internet

A project can forward requests to a real API, its upstream, and keep each exchange as a capture you can later turn into a mock. Gateway modes explains the two forwarding modes; this page sets one up.

  1. Open the project’s Settings tab.

  2. Under Responses and logging, check that Store request logs is on. Without it, requests are still forwarded, but nothing is kept.

  3. In Body keys to redact in captures, enter each field that must never be stored, such as customerRef, pressing Enter after each, and select Save settings. Captures explains what redaction covers.

  4. Open the project’s Captures tab. Under Recording, select Start recording.

  5. In What answers a request, keep Proxy unmatched to keep using your mocks and forward only what they miss, or choose Record everything to forward every request and leave your mocks out while you record.

  6. Enter the Upstream base URL, such as https://api.example.com/v2.

  7. Select Save recording.

  8. The dialog Start forwarding to the upstream? names the upstream. Select Start forwarding.

  9. Send requests to the project’s address, the way your client would call the real API:

    Terminal window
    curl "https://orders-api.mockhub.dev/orders?page=2"
  10. Watch the Captures tab: while it shows Live, what was recorded appears there as requests are forwarded.

“Recording settings saved” confirms the change, and it applies from the next request. Each forwarded request gets the upstream’s answer: GET /orders?page=2 above goes to https://api.example.com/v2/orders?page=2. In Request logs it shows as Forwarded to your upstream, and Captures groups it by endpoint under a Recording everything or Proxying unmatched requests tag.

Recording on the Captures tab shows the mode and the upstream address. It warns when Store request logs is off, since nothing is then kept, and when the workspace’s upstream allowance is used up. To change the address, or the mode, select Change; moving traffic to another address, or from Proxy unmatched to Record everything, asks Change forwarding? first.

If saving is refused, the form says why under Upstream base URL, such as:

Message What to do
Forwarding needs an upstream URL. Enter the Upstream base URL.
Enter a full http:// or https:// URL. Include the scheme, such as https://.
Host “…” resolves to …, which is not a public address. Use an address on the public internet: private networks are always refused.
Host “…” does not resolve to any address. Check the hostname; it must exist in public DNS.

A capture is the request log of one forwarded exchange: the request as your client sent it, and the response as the upstream gave it. It follows the project’s logging settings, so by default the values of its Authorization and Cookie headers are stored as [REDACTED], and it is kept for as long as the plan keeps request logs. Unlike other unmatched requests, captures are kept whether or not Log requests no mock answered is on.

What goes to the upstream is your client’s request, headers included, with Host set to the upstream’s own name. A credential your client sends therefore reaches the real API, as it would without MockHub in between.

When the upstream cannot be reached or answers with more than the plan allows, your client gets a 502 with a plain-text reason, and that answer is captured too. Its row in the request logs is tagged Upstream unreachable, and contract checks leave it out, because it is MockHub’s answer and not your upstream’s. See Requests get 502 Bad Gateway. When the workspace already has three outgoing requests under way (forwards, webhook deliveries and alerts count together), your client gets a 429 instead and nothing is forwarded or captured; see Requests get 429 Too Many Requests.

A real sandbox often needs a key your tests should not hold. Store it in the project and MockHub adds it to every forwarded request.

  1. On the Captures tab, under Recording, select Change.

  2. Under Upstream headers, select Add header, enter the name, such as Authorization, and the value, such as Bearer <sandbox key>.

  3. Select Save recording.

The header replaces the caller’s header of the same name, so a placeholder your client sends never reaches the upstream. MockHub stores the value encrypted and never shows it again, and it is not written to request logs, captures, mocks promoted from them, the audit trail, a configuration export or a pack. Hidden; type to replace marks a stored value: leave it blank to keep it. To remove a header, delete its row. In a configuration document the section is settings.upstreamHeaders, with values such as ${env:SANDBOX_KEY}.

The headers belong to one upstream. If you change the Upstream base URL to another address, every stored value must be typed again, or the header deleted, so a key for one host never follows the project to another. A different path on the same address keeps them.

If the upstream echoes a value back in a response header or body, such as a debugging endpoint or an error that quotes your key, the capture and the request log store it as [REDACTED], and the log’s details count the body or header as redacted. Your client still receives what the upstream sent.

Every forwarded request counts against the workspace’s upstream allowance, a number per day and per month that the plan sets and every project in the workspace shares, as well as against the plan’s request limits. The limits page lists the amounts.

Settings → Subscription shows how much of it is used. When it runs out, a request that needs forwarding gets a 429 until the daily or monthly reset; see Forwarding.

On the Captures tab, select Stop recording under Recording. It asks nothing first: “Recording stopped” confirms it, and the project answers from its mocks again with the next request. Captures already stored stay, and the upstream address is kept for next time, so Start recording offers it again.

A project keeps its mode when the workspace moves to a plan without forwarding, but nothing is forwarded any more: it answers from its mocks, and a request no mock matches gets a 404. The Captures tab says the project is still set to forward, and still lists what was recorded before, which can be reviewed and turned into mocks. The project’s other settings can still be saved.

The saved mode applies again once the plan includes forwarding. To keep the project on its mocks after an upgrade, an Admin selects Switch to Mock only on the Captures tab.

Stored upstream headers are kept too, and are not sent while the plan leaves out forwarding. To delete them, an Admin selects Remove upstream headers on the Captures tab; their values then have to be typed again to send them after an upgrade.

  • When the upstream allowance runs out, every request that needs forwarding gets a 429. In Record everything that is every request; Proxy unmatched still answers from mocks.
  • A project has one upstream. To record two APIs, use two projects.
  • At most 20 upstream headers, each value up to 4,096 bytes; a character outside ASCII takes two to four. Host, Content-Type, Content-Length, Transfer-Encoding, the X-Forwarded-* names and every X-MockHub-* name are refused. They are request headers only; MockHub does not rewrite the upstream’s answer.
  • A value an upstream echoes back is hidden in the log when it is 8 characters or longer and appears as a whole word, a full stop at the end of a sentence included. It is also found in common encodings. A copy the upstream changes in other ways, or one inside a compressed body, can be stored as sent, so don’t rely on this alone to keep a secret out of the logs. If MockHub cannot check a body, it stores a placeholder rather than the body.
  • Adding or changing upstream headers needs a plan with forwarding; deleting them never does.
  • In Proxy unmatched, a running chaos profile shapes forwarded answers; see Create a chaos profile. While Record everything is on, scenarios, response sequences and chaos profiles do not run; see The three modes.
  • In the demo, a project can record only MockHub’s sample API. Your own API needs an account.
  • A browser’s preflight is answered by MockHub, and neither forwarded nor recorded, unless the project’s Browser access (CORS) is Off; see Let web pages call a project.

Report a problem with this page