Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

apimock.toml root settings

The root config file’s four top-level tables. All are optional — an empty or missing apimock.toml is valid, and falls back to zero-config, port-3001, serve-./-by-path behaviour.

[listener]
ip_address = "127.0.0.1"
port = 3001

[listener.tls]
cert = "./cert.pem"
key = "./key.pem"
# port = 3002   # omit to serve HTTPS-only on `listener.port`
# handshake_timeout_seconds = 10
# max_connections = 256

[log]
verbose = { header = true, body = true }

[service]
strategy = "first_match"
rule_sets = ["apimock-rule-set.toml"]
middlewares = ["apimock-middleware.rhai"]
fallback_respond_dir = "."
# cors_allow_credentials_origins = ["https://app.example.com"]
# max_request_body_bytes = 33554432
# middleware_max_operations = 10000000

[file_tree_view]
show_hidden = false
builtin_excludes = true
extra_excludes = ["*.bak"]
include = []
respect_gitignore = false

[listener]

FieldTypeDefaultMeaning
ip_addressstring"127.0.0.1"Bind address
portinteger3001Bind port

ip_address accepts any address your OS can bind to, IPv4 or IPv6:

ip_addressBinds to
127.0.0.1 / ::1Loopback only (the default)
A LAN address, e.g. 192.168.1.10That interface
0.0.0.0 / ::Every interface — reachable from outside the machine

Binding to 0.0.0.0/:: or a LAN address exposes the mock server beyond localhost — fine on a trusted network, a real exposure on anything else.

[listener.tls]

Enables HTTPS. Both cert and key must point at files that exist — checked at startup, not lazily.

FieldTypeDefaultMeaning
certstringPath to the certificate PEM file
keystringPath to the private key PEM file
portinteger, optionalIf set, HTTPS listens here and plain HTTP continues on listener.port. If omitted, listener.port itself becomes HTTPS-only — no plaintext HTTP listener starts at all
handshake_timeout_secondsinteger10An incomplete TLS handshake is dropped after this long
max_connectionsinteger256Maximum concurrent HTTPS connections. Beyond this, a new connection waits for a slot rather than being refused — the server recovers as soon as one closes

Relative cert/key paths resolve against the process’s current directory, not against apimock.toml’s own location — unlike rule_sets and fallback_respond_dir below, which do resolve relative to the config file. Run apimock from the directory containing the cert/key files, or use absolute paths. See Serve over HTTPS for a full working example.

A cert/key that exists but fails to parse stops startup — the server never binds any listener, HTTP included. Before this was fixed, a malformed PEM silently fell back to HTTP-only, which is worse than a loud failure: an operator who configured HTTPS would not otherwise know they didn’t get it.

[log]

FieldTypeDefaultMeaning
verbose.headerboolfalseLog request headers. Credential-bearing headers (authorization, cookie, set-cookie, proxy-authorization, x-api-key) print as [redacted] — same policy, same defaults, as the trace channel (RFC 040, RFC 051)
verbose.bodyboolfalseLog request bodies and query strings. Redacted (RFC 073) — a query-string value or JSON body field whose key matches the same credential denylist that already governs headers (token, password, api_key, and friends — see the threat model) prints as [redacted], recursively for nested body fields; everything else prints verbatim

[service]

FieldTypeDefaultMeaning
strategystring or table"first_match"Default response strategy — see Vary the response for one path for all five and their syntax
rule_setsarray of strings, optionalRule-set files, checked in this order — see Rule-set schema
middlewaresarray of strings, optionalRhai middleware files, checked in this order before any rule set — see Script with Rhai middleware
fallback_respond_dirstring"."Directory served by URL path when nothing above matches
cors_allow_credentials_originsarray of strings, optional[]Exact origins (beyond the always-allowed http://localhost:* / http://127.0.0.1:*) allowed credentialed CORS reflection — see Response headers
max_request_body_bytesinteger33554432 (32 MiB)A request body over this size is refused with 413, before it is buffered
middleware_max_operationsinteger10000000Rhai operations one middleware evaluation may perform before it’s aborted — see Script with Rhai middleware

Relative rule_sets and fallback_respond_dir paths resolve against apimock.toml’s own directory, regardless of the process’s current directory when apimock was started.

[file_tree_view]

This does not affect what the running server serves over HTTP. It filters the file tree shown by the Workspace config-editing API (consumed by GUI tooling, and incidentally by apimock validate’s internal rule/rule-set count) — not the fallback_respond_dir request path. A file inside node_modules, .git, or any excluded pattern here is still served over HTTP if a client requests its exact path.

FieldTypeDefaultMeaning
show_hiddenboolfalseShow dotfiles and dot-directories in the editor’s file-tree view
builtin_excludesbooltrueApply the built-in exclude list (below)
extra_excludesarray of glob strings[]Additional excludes, matched against each entry’s bare filename (not its full path)
includearray of glob strings[]An allow-list — only applies to files, never to directories
respect_gitignoreboolfalseAlso exclude anything a .gitignore (found by walking up from the listed directory, stopping at the first .git) would ignore

Built-in excludes (when builtin_excludes = true, matched by exact bare name): target, node_modules, dist, build, out, __pycache__, .venv, vendor, .cargo, .gradle, .idea, .vscode. Note .git itself is not in this list — it’s hidden by the separate dotfile filter when show_hidden = false, but would reappear in the editor’s view if show_hidden = true and .git isn’t added to extra_excludes explicitly.

extra_excludes and include both use standard glob syntax (*, ?, […]) via the globset crate. Filter order, each one able to reject an entry outright: dotfile filter → built-in excludes → extra_excludes.gitignoreinclude (files only).