Mock Rules
Intercept matching requests and return fake responses instead of hitting the real server. Perfect for offline development, testing error states, and simulating API behavior.
Mock rules are static. They can match by URL, method, and request headers, but they do not maintain server-side state or branch on request bodies.
Web UI
Open Mock Rules from the Rules group. The page provides:
- A form to create mock rules with Name, URL Pattern, Match Type (exact/wildcard/regex), Method, Header Conditions, Status Code, Response Headers, Response Body, File Path, Directory Path, Delay, and Priority
- A list of all mock rules with enable/disable toggles
- Edit and delete buttons for each rule
- Active/inactive status indicators
When you create a mock rule for an HTTPS URL, APXY automatically enables SSL interception for that domain.
The Web UI creates and edits global rules only. It shows the rules of each workspace read-only, with the path of their file.
Where mock rules live
A mock rule made with the CLI or MCP in a git worktree goes to <worktree>/.apxy/rules.json. It answers the requests of that worktree only, such as requests that apxy run sends from it. Add --global to write ~/.apxy/rules.json instead. A global rule answers untagged traffic, such as browsers on the system proxy and iOS simulators, and every workspace after its own rules. Outside any workspace, mock rules are global. See Workspaces.
CLI
All apxy mock … subcommands (add, list, enable, disable, remove, clear) and flags are documented in CLI Reference → Mock.
Quick example:
apxy mock add \
--name "Mock Users" \
--url "https://api.example.com/api/users" \
--match exact \
--status 200 \
--body '{"users": [{"id": 1, "name": "Test User"}]}'Match types
| Type | Description | Example |
|---|---|---|
exact | URL must match exactly | /api/users matches only /api/users |
wildcard | * matches any characters | /api/* matches /api/users, /api/posts |
regex | Full regular expression | /api/users/\d+ matches /api/users/123 |
Use Cases
Testing error handling
Add a mock rule that returns 5xx or 4xx responses for a path you need to exercise in the client.
Offline development
Stub critical endpoints with small JSON bodies so the app runs without the real backend.
Simulating slow responses
Use the Delay field (or --delay in the CLI) to mimic sluggish upstream APIs.