How MockHub handles a request
A request to a project’s hostname passes through the same steps in the same order every time. The order explains most surprises: why a request was refused before any mock was consulted, why a 404 did not appear in the log, why a retry was throttled.
1. The hostname picks the project
Section titled “1. The hostname picks the project”The host part of the address, such as orders-api.mockhub.dev, identifies exactly one project. A hostname that belongs to no project is answered with a 404 and is not recorded anywhere.
Paths starting with /__admin are reserved and always answer 404, whatever mocks exist.
2. The domain decides the scheme
Section titled “2. The domain decides the scheme”Whether a hostname answers over HTTPS, HTTP or both is a setting of its domain, shared by every project on it. A plain http:// request to an HTTPS-only domain is redirected to the same address over HTTPS. Neither the redirect nor a refusal is logged or counted. See Hostnames, domains and protocols.
A browser’s OPTIONS preflight is answered right after this step, with 204, unless the project’s CORS is Off, or it has an OPTIONS mock and is not in Record everything. It is neither logged nor counted, and because it comes before every refusal below, the page can read the refusal that follows. From here on, every answer carries the project’s CORS headers; see Let web pages call a project.
3. The workspace and the project must be able to serve
Section titled “3. The workspace and the project must be able to serve”The request is refused, before anything is counted against your limits, when:
| Answer | Why |
|---|---|
| 402 | The workspace is suspended because of a billing problem, or needs a subscription before it can serve. |
| 410 | The request reached a demo project whose demo has ended. |
| 403 | The project is archived, or is outside the number of projects the plan lets run. |
Nothing is deleted in any of these cases. Fixing the cause restores the address as it was.
4. The plan’s limits apply
Section titled “4. The plan’s limits apply”Next come the limits of the workspace’s plan, shared by every project in the workspace:
- a request body larger than the plan allows is refused with 413;
- too many requests in flight at once, or too many in a second, hour, day or month, are refused with 429. When the limit resets at a known time, a
Retry-Afterheader says when to try again.
Plans, quotas and limits explains how these limits work.
5. The inbox answers its own path
Section titled “5. The inbox answers its own path”A request to /__inbox or any path under it is recorded in the project’s inbox and answered with 200 and {"received": true}, whatever the method. No mock can answer on that path. The inbox is for receiving callbacks from services you are testing.
6. The gateway mode decides who answers
Section titled “6. The gateway mode decides who answers”Each project has a gateway mode, chosen in What answers a request:
- Mock only: the project’s mocks answer, and a request no mock matches gets a 404.
- Proxy unmatched: mocks answer first, and a request no mock matches is forwarded to the project’s upstream.
- Record everything: every request is forwarded to the upstream and mocks are not consulted.
See Gateway modes.
A request that asks for one of a mock’s responses with X-MockHub-Response is checked before the mode decides anything. A value that is not <mock reference>:<response key>, or is repeated, is refused with 400 Response selector malformed. In Record everything, where no mock runs, a request that sends it is refused with 422 Response selection unavailable rather than forwarded.
7. A mock matches, and chaos may change the answer
Section titled “7. A mock matches, and chaos may change the answer”Active mocks are compared with the request’s method, path, query parameters, headers and body, and with the state of any scenario they belong to. See Request matching. The mock found then answers with its default response, the next step of its sequence, or the response the request asked for; a request that asked for one it cannot get is refused with 422 and never answered with the default or forwarded to the upstream. See Choose the response that answers.
If a chaos profile is active on the project, it can delay a matched mock’s response, whichever of its responses answers, replace it with an error, or fail the connection. An unmatched request in Mock only is never affected by chaos. In Proxy unmatched, the same profile also shapes a request forwarded to the upstream: latency is added to the upstream’s time, and an injected error or connection fault is answered without calling it.
A response larger than the plan’s traffic response body limit, or one that takes longer than 70 seconds from arrival to answer, fails with 502. A simulated delay counts towards that deadline. A stream does not: its chunks are sent after the answer is ready, within the plan’s stream limit.
When the answer depends on a scenario’s state or a response sequence’s place and MockHub cannot read or save it, no mock answers: the request gets 503 with Scenario unavailable, and is not forwarded to the upstream.
8. The exchange is recorded and triggers fire
Section titled “8. The exchange is recorded and triggers fire”What happens after the response depends on the project’s settings:
- The request and response are written to the request log, with the details the logging settings allow. A request no mock matched is logged only while Log requests no mock answered is on, as it is for a new project, except that a request forwarded to the upstream, and an error MockHub answered with itself, such as a
502, are logged either way. - Insights count the request in the project’s traffic, match rate and timing. Unmatched requests are counted only when they are logged.
- If the mock that answered has a webhook trigger, the webhook is sent.
Recording happens after the response is sent, so a slow log never slows your caller down. A request appears in the log a moment after it was answered.