Use case
A common workflow looks like this:- Run your application against the real service, with MockServer acting as a proxy.
- MockServer records every request and the corresponding response.
- You retrieve the recordings and convert them into expectations.
- In CI, your application runs against those mock expectations instead of the real service.
Step-by-step workflow
Start MockServer
Start MockServer on any available port. For the web proxy or SOCKS proxy, no extra configuration is needed beyond specifying the port.Or via Docker:
Configure your application to proxy through MockServer
Point your application at MockServer. For JVM-based applications, set the standard proxy system properties:For other clients, see Proxy Overview for per-client configuration examples.
Run your application against the real service
Exercise the functionality you want to record. MockServer forwards every request to the real upstream service and stores a copy of the request and response internally.All proxied requests are recorded in the order they are received.
Retrieve recorded expectations
Once your application has run, retrieve the recorded expectations using the REST API, Java client, or JavaScript client.MockServer returns the expectations as a JSON array. Each expectation contains the recorded
httpRequest and httpResponse.Convert recordings into mock expectations
Register the recorded expectations back into MockServer (or a fresh instance) so they are served as mocks. You can post the JSON output directly back to the expectations endpoint, or edit it first to adjust request matchers or responses.In CI, start MockServer without the proxy configuration and load these expectations at startup — your application will receive the same responses it got from the real service during recording.
Filtering recorded expectations
Pass a request matcher to retrieve only the expectations you care about. This is useful when your application talks to multiple services and you want to isolate recordings for one path or method.Retrieving other recorded data
In addition to full expectations, MockServer lets you retrieve recorded requests or request-response pairs in isolation.Recorded requests only
Recorded requests and responses
Output format
By default, recorded expectations are returned as JSON. You can also request Java code format, which generates ready-to-useMockServerClient calls you can paste directly into your test setup.
All recorded data is stored in memory. If you restart MockServer, recordings are cleared. Export and persist the JSON output before restarting if you intend to reuse it.