Skip to main content
MockServer maintains internal state that you can inspect, clear, and persist:
  • Recorded requests — every request received since MockServer last started or was reset
  • Active expectations — all currently registered expectations
  • Recorded expectations — expectations captured from proxied traffic
  • Logs — all internal log events

Log levels

The log level controls how much detail MockServer records. Set it using the mockserver.logLevel property or MOCKSERVER_LOG_LEVEL environment variable. Change the log level at runtime without restarting MockServer:
Use DEBUG when debugging why an expectation is not matching. Use INFO for normal operation. Use OFF only if logging overhead is a concern and you have no need to inspect state.

Retrieving recorded requests

Retrieve all requests MockServer has received since it last started or was reset:
Filter by request properties to retrieve only matching requests:

Retrieving active expectations

Retrieve all currently registered expectations:
Filter by request matcher to retrieve only expectations that match certain request properties:

Retrieving recorded logs

Retrieve the log messages MockServer has recorded:
Filter logs to only those related to a specific path:

Clearing state

Clear state selectively using the type parameter. This is useful between tests to remove expectations or logs without fully resetting MockServer.

Clear all state matching a request path

Clear only logs for a specific path

Clear only expectations for a specific path

When logLevel is set to DEBUG, clear operations mark log entries as deleted rather than removing them. This keeps the UI’s log history intact so you can still debug interactions that occurred before the clear.

Resetting all state

Reset removes all recorded requests, all active expectations, all recorded expectations, and all logs:
Reset is irreversible. All state is discarded immediately. If you need to recover expectations, persist them first (see below).

Persisting expectations

By default, expectations exist only in memory and are lost when MockServer restarts. Enable persistence to write expectations to a JSON file that MockServer reloads on startup.

Enable persistence

1

Set the persistence properties

2

Confirm the file is reused on restart

Set persistedExpectationsPath and initializationJsonPath to the same file so MockServer both writes to and reads from the same location. On each restart, MockServer loads expectations from this file before accepting requests.
MockServer updates the persistence file automatically whenever expectations are added, cleared, or expire. To watch the initialization file for external changes and reload expectations without restarting: