[ AxiomCore · Documentation ]
Mocks
Serve deterministic static, conditional, stateful and fault-injected responses from endpoint MockConfig declarations with axiom mock.
A contract mock answers requests from mock(MockConfig(...)) declarations on
your endpoints, so you can build and test a client before the backend exists.
axiom mock FILE.acore --profile contract starts the mock engine locally.
Pick a mock profile
| Command | Profile | Serves |
|---|---|---|
axiom mock FILE.acore --profile contract | Contract | Endpoint MockConfig responses from source |
axiom mock FILE.acore | auto (default) | Full server simulation when compiling the source produces a private server plan; contract mocks otherwise |
axiom mock --cloud | Cloud contract mocks | Mocks of the linked Cloud project; needs a linked project and a Cloud session |
axiom serve FILE.acore --mock | Server simulation only | Always requires a server plan and bound fixtures |
auto never downgrades: a broken or unsupported server plan fails instead of
falling back to contract mocks. axiom serve starts real backend execution,
defaults to local axiom.acore, and never downloads Cloud mocks. With no input,
axiom mock uses axiom.acore in the current directory. Cloud mocks keep the
configuration cache and its ETag; see Cloud mocks.
Declare an endpoint response
endpoint listTasks(method: GET, path: "/tasks") {
response(type: Json)
mock(MockConfig(
fallback: MockResponse(
status: 200,
headers: { "content-type": "application/json" },
data: StaticData(body: { tasks: [] })
)
))
}axiom mock axiom.acore --profile contract --port 8080 --debugThe server listens on 127.0.0.1:8080 by default (--host, --port).
--debug prints redacted startup diagnostics, never raw credentials or
request and response bodies.
| Route | Purpose |
|---|---|
| Your endpoints | Mock responses |
GET /axdoc, GET /axdoc/openapi.json | Generated API docs and OpenAPI |
GET /_axiom/health | Health check |
POST /_axiom/state/reset | Restore the initial state and reset sequential selection |
On a loopback listener these routes are open. On a non-loopback listener the
server issues a private X-Axiom-Sandbox-Key, writes it to an owner-only
credentials.json reported at startup, and requires it on every route, docs,
health and reset. Only the landing page at / stays open.
Responses and selection
MockResponse field | Default | Meaning |
|---|---|---|
status, headers | 200, none | Response status and headers |
data | Empty StaticData | The body strategy (see below) |
conditions | None | All must match for this response to be eligible |
delayMs, delayJitterMs | 0 | Fixed and random added latency |
weight | 1 | Used by weighted selection |
label | None | Name used by state changes |
MockConfig has enabled (default true), responses, selectionStrategy
(first_match by default, or random, sequential, weighted), fallback,
state and fault.
MockConfig(responses: [
MockResponse(
label: "missing",
conditions: [PathCondition(key: "id", op: "eq", value: "404")],
status: 404
)
])| Condition | Inspects |
|---|---|
HeaderCondition(key, op, value) | A request header (default op exists) |
QueryCondition(key, op, value) | A query parameter |
PathCondition(key, op, value) | A path parameter |
BodyCondition(path, op, value) | A value in the JSON body |
StoreCondition(key, op, value) | Mock state (default op gt) |
AllCondition, AnyCondition, NotCondition | Combine other conditions |
Condition operators are eq, neq, exists, missing, contains,
matches, gt and lt.
| Data strategy | Produces |
|---|---|
StaticData(body) | A fixed body |
TemplateData(body) | A body with placeholders such as {{ request.path.id }}, {{ request.body.title }}, {{ store.tasks }} or generated {{ faker.uuid }} values |
CollectionData(item, count, paging) | A list of count items (default 20); PagingConfig reads limit and offset |
EchoData(body) | Values copied from the request or state |
StoreQueryData(key, filterKey, filterValue, returnAll) | Items read from mock state |
Generated faker values change on every request. Use StaticData when a test
asserts exact values.
Stateful behavior
MockConfig(state: MockStateConfig(
initial: { tasks: [] },
onReceive: [StoreMutation(type: "append", key: "tasks", value: { id: "1" })]
))StoreMutationtypes areincrement,increment_fields,set,update,update_all,appendanddelete, with optionalby,filterKeyandfilterValue.- Mutations run in declaration order.
MockStateConfig.changesholds conditionalStateChangeentries. Each can match a selected response byresponseLabel, testwhenconditions, applymutationsand appendeventsto the activity list named byactivityKey(defaultactivity). Every matching change runs in order, so a later change can read state an earlier one wrote.- State is shared and in memory. Reset it with
POST /_axiom/state/resetor a restart when a test needs isolation.
Fault injection
MockConfig(fault: FaultConfig(
errorRate: 0.1,
errorResponse: MockResponse(status: 503),
networkFault: NetworkFault(type: "slow_response", probability: 0.1, delayMs: 500)
))NetworkFault type | Behavior |
|---|---|
slow_response | Adds delayMs before responding |
timeout | Waits 30 seconds, then returns 408 |
connection_reset | Returns 502 |
errorRate and probability must be between 0 and 1 (probability defaults to
1). Fault injection shows how a consumer handles failures; it does not estimate
a production service's reliability.
Reload on save
axiom mock axiom.acore --profile contract --watch --port 8080--watch needs .acore source and a fixed loopback port. Invalid source keeps
the last valid mock running; a successful reload starts with fresh state. A
reload cannot switch profiles, so a change that adds a private server plan
needs a restart. Cloud and artifact inputs do not support --watch.
Checklist
- Inspect the evaluated contract (
axiom eval) before starting the server. - Test response selection and the fallback explicitly.
- Reset state between tests that need isolation.
- Keep real credentials out of headers and templates.
- Run the same client suite against the real backend before release.
Next steps
- Simulate managed actions with server simulation.
- Assert on mock responses with contract tests.
- Look up every mock class in the Acore schema reference.
- Host mocks in Axiom Cloud.