Skip to main content

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​

  1. Open API Mock from the Studio navigation.
  2. Select + New.
  3. Enter a descriptive Label.
  4. Select an HTTP Method. Supported methods include GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, and ANY.
  5. Enter a Path, such as /api/users/:id.
  6. Choose the response Status Code, Content Type, and optional Delay (ms).
  7. Enter the response body.
  8. 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​

  1. Select an endpoint from the left panel.
  2. Update its request match or response configuration.
  3. Select Save.

Changes affect subsequent requests. Coordinate edits if the endpoint is shared by tests or other developers.

  • 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.