Mock servers
A mock server simulates your API by answering with the examples saved in your requests. Handy so the frontend can move forward before the backend exists, for demos, or for tests that must not touch production.
Create a mock
Section titled “Create a mock”- Save examples in your requests: send the request and click the save icon in the response, or create them in the Examples tab.
- Go to Mock servers → New, pick the collection and optionally an environment (to resolve
{{variables}}in the examples) and a delay. - Copy the URL:
https://YOUR-CARTERO/mock/abc123.
If an example request is GET {{baseUrl}}/users/:id, the mock answers GET https://YOUR-CARTERO/mock/abc123/users/42.
How it picks the response
Section titled “How it picks the response”- The method must match.
- The path must match segment by segment.
:paramand{{variable}}match any value, but an exact path beats one with parameters. - Matching query params add points.
- On a tie, 2xx responses are preferred.
You can force an example with request headers:
| Header | Effect |
|---|---|
x-mock-response-name: Post not found |
Uses the example with that name |
x-mock-response-code: 404 |
Uses an example with that status code |
x-mock-response-id: <id> |
Uses that exact example |
x-mock-match-request-body: true |
Requires the body to match |
x-mock-match-request-headers: X-Tenant |
Requires those headers to match |
If no example matches but the request has a contract, the mock builds a response that follows it. If there’s no contract either, it returns 404 with an explanatory message.
Dynamic responses
Section titled “Dynamic responses”In an example body you can use dynamic variables, which change on every call:
{ "id": "{{$guid}}", "email": "{{$randomEmail}}", "created": "{{$isoTimestamp}}" }Private mocks and call log
Section titled “Private mocks and call log”- Private: requires an API token in the
x-api-keyheader. - Incoming calls: the panel shows every call, which example answered and when.
- The mock supports CORS, so you can call it directly from a web page.