Prerequisites
Before you begin, ensure you have:- Completed the Running on Kubernetes guide
- WireMock Runner deployed and running in your Kubernetes cluster
- WireMock CLI installed and authenticated
- Access to the services you want to record (either real APIs or test environments)
Set up a development environment
Next we’ll set up a development environment in WireMock Cloud (an environment is a set of mock APIs intended to be used together).Initialise environment and profile
Run the following to create a new environment in WireMock Cloud and also create a new profile, which will be defined inwiremock-development.yaml and maps the local services to the corresponding cloud IDs for the APIs we just created:
Push existing stubs
If you have existing stub mappings in your local.wiremock directory, push them to your development environment:
Set the profile in the Runner
When the Runner starts we need to set it to use the profile we just created, so add the following to thewiremock-runner container envrionment variables in the Kubernetes manifest in wiremock-runner.yaml:
Start Recording
Switch the Runner to record-many mode using the Runner’s admin API:.wiremock/wiremock.yaml file and recording the responses.
Make requests to record
Make requests to the API endpoints you want to record. The Runner will forward these to the real API and capture both the request and response. For example, to record a GitHub organizations endpoint:Flush recorded stubs
Flush the recorded stubs to ensure they’re saved to WireMock Cloud:Always flush before stopping recording or switching modes. The Runner does not automatically flush when switching modes, so any unflushed recordings will be lost.
Stop recording
Switch the Runner back to serve mode:Test your recorded stubs
Test in WireMock Cloud
Use the base URLs you noted earlier to test the recorded endpoints directly in WireMock Cloud:Pull changes to your local environment
Pull the newly recorded stubs down into the local project:Test in Kubernetes
Test the recorded endpoints again to ensure they’re working correctly:Next steps
- Learn how to promote your mock APIs between environments using Git and CI/CD.
Additional resources
- Explore selective recording to record only specific services
- Configure batching options to control when recordings are flushed