Getting Started

Mock API Server User Guide

A practical guide for first-time users to create reliable mock APIs quickly.

Quick Start

  1. Create a mock server with a name and key. The key becomes part of the runtime URL.
  2. Call `/mock/{serverKey}/...` from your app, Postman, browser, or test runner.
  3. Set a useful default response so unmatched requests still return something meaningful.
  4. Add rules from top to bottom. The first matching rule is the one that responds.
  5. Use request logs to confirm the incoming request and the returned payload.

How Matching Works

  1. Method: `ANY` matches all verbs, or choose a specific one like `GET` or `POST`.
  2. Path Match: `Exact`, `Prefix`, `Contains`, and `Regex` give you different routing behavior.
  3. Conditions JSON: add header, query, body, or JSON field checks before a rule can match.
  4. Weighted Responses: simulate success and failure mixes with different weights.
  5. Delay: imitate slow upstream systems when you need realistic timing.

Import And Export

  1. Use Export in Server Settings to download the selected server as JSON.
  2. The file includes server settings, fallback behavior, default headers, rules, conditions, state actions, and responses.
  3. Runtime logs and current state values are not included in the export.
  4. Use Import Server in the Servers card to create a new server from a JSON export.
  5. If the imported key already exists, the app creates a nearby key such as `orders-sandbox-import`.

Use It Effectively

  1. Create one mock server per system or scenario such as `orders-qa` or `mobile-demo`.
  2. Use regex named captures when your response needs IDs from the path.
  3. Use counters and state values when a sequence of requests should change future responses.
  4. Seed counters in the State panel when you want a non-zero starting point before testing.
  5. Keep the latest request log visible while testing so you can spot bad routes quickly.
  6. Clear logs between test runs when you want a clean history for a fresh scenario.

Supported Tokens

These tokens are supported by the runtime in response templates, headers, default bodies, and state action value templates.

Request Tokens

  • {{request.method}}
  • {{request.path}}
  • {{request.relativePath}}
  • {{request.queryString}}
  • {{request.body}}
  • {{request.json.items[0].tripNumber}}
  • {{request.header.<name>}}
  • {{request.query.<name>}}

Route And State

  • {{route.<captureName>}}
  • {{state.counter.<name>}}
  • {{state.kv.<name>}}
  • {{state.list.<name>}}

Generated Values

  • {{faker.name}}
  • {{faker.email}}
  • {{faker.company}}
  • {{faker.city}}
  • {{randomInt:min:max}}
  • {{now}}
  • {{uuid}}

Example Snippets

These examples match the supported request, state, and weighted response features.

Conditions JSON

[
  { "type": "HeaderEquals", "key": "x-env", "value": "qa" },
  { "type": "JsonPathEquals", "key": "order.status", "value": "draft" }
]

State Actions JSON

[
  { "type": "SetCounterIfMissing", "name": "orders", "valueTemplate": "100" },
  { "type": "IncrementCounter", "name": "orders" },
  { "type": "SetCounter", "name": "sequence", "valueTemplate": "1000" },
  { "type": "SetKeyValue", "name": "lastOrderId", "valueTemplate": "{{uuid}}" },
  { "type": "AppendListItem", "name": "requests", "valueTemplate": "{{request.body}}" }
]

Responses

[
  {
    "name": "success",
    "weight": 80,
    "status": 201,
    "contentType": "application/json",
    "headers": {
      "x-mock-source": "mock-api-server"
    },
    "bodyTemplate": "{ \"id\": \"{{uuid}}\", \"status\": \"created\" }"
  },
  {
    "name": "validation-error",
    "weight": 20,
    "status": 422,
    "contentType": "application/json",
    "headers": {},
    "bodyTemplate": "{ \"error\": \"Invalid order\" }"
  }
]

Counters And Request Logs

  1. IncrementCounter adds `1` every time the rule matches.
  2. SetCounter forces a counter to a specific whole number every time the rule matches.
  3. SetCounterIfMissing seeds a counter once, then leaves future requests free to continue incrementing.
  4. Use the State panel to add counters manually and save starting values like `100` or `1000`.
  5. Request logs now show the exact endpoint, response time, request payload, and response body in collapsible sections.