Creating Mock API Endpoints
Use API Mock to create predictable HTTP endpoints while a real dependency is unavailable or difficult to reproduce. A mock can return a fixed or templated response, a chosen HTTP status, content type, and optional delay.
Create an endpoint
- Open API Mock from the Studio navigation.
- Select + New.
- Enter a descriptive Label.
- Select an HTTP Method. Supported methods include GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, and ANY.
- Enter a Path, such as
/api/users/:id. - Choose the response Status Code, Content Type, and optional Delay (ms).
- Enter the response body.
- Select Save.
Use delay to reproduce timeout and loading behavior. Use non-success status codes to validate error handling in clients and workflows.
Create a dynamic response
Response templates can use request data and generated values. Common expressions include:
{{request.params.id}}
{{request.query.page}}
{{request.body.name}}
{{faker "person.fullName"}}
{{faker "internet.email"}}
{{now}}
{{uuid}}
For example:
{
"id": "{{request.params.id}}",
"name": "{{faker \"person.fullName\"}}",
"receivedAt": "{{now}}"
}
Keep the rendered response valid for the selected content type. For JSON responses, quote expressions that return strings.
Edit an endpoint
- Select an endpoint from the left panel.
- Update its request match or response configuration.
- Select Save.
Changes affect subsequent requests. Coordinate edits if the endpoint is shared by tests or other developers.
Recommended practices
- Match the real API's path, content type, and representative status codes.
- Create separate endpoints for materially different behaviors instead of frequently editing one shared mock.
- Never place production secrets or personal data in mock response bodies.
- Add a delay only when the test specifically needs latency.
- Treat mocks as development aids, not as production dependencies.
Troubleshooting
- The request does not match: verify the method and path, including path-parameter placement.
- The response is invalid: validate the body against the selected content type and check template quoting.
- A template value is empty: confirm the incoming request contains the referenced parameter, query value, or body field.