Multi-domain recording using the WireMock CLI
How to use the WireMock CLI to record stubs from multiple private endpoints
The CLI offers a convenient way to record stubs from multiple endpoints that are accessible from the computer running
the CLI, but not accessible from the internet. This is achieved by the use of the cli record-many
command and the
WireMock environment config file. The environment configuration file specifies all the services you are recording:
In the above configuration file, the cloud_id
field specifies the Mock API you want to save to where <mock_api_id>
is the ID of the Mock API that should receive the recorded stubs. At present you can get that value by browsing into a
Mock API at https://app.wiremock.cloud and extracting it from the URL - for instance in the URL
https://app.wiremock.cloud/mock-apis/33eye3l9/stubs/1e0d7dc0-06a0-49a2-81a7-f5d6a40bfa3d
, the ID is 33eye3l9
.
If you don’t already have a Mock API in WireMock Cloud that you are recording to, you can omit the cloud_id
field
from your service definition and the WireMock CLI will create a new Mock API for you before saving the recorded stubs.
The environment config file will be updated with the id of the created Mock Api.
The type
field specifies the type of the Mock API you are saving to. This field allows the 4 Mock API types supported
by WireMock Cloud:
- openapi
- grpc
- graphql
- unstructured
The port
field allows you to specify the port number the WireMock CLI will listen on when recording to the endpoint
specified in the originals
-> default
field. The port
field specified should be unique across all the services
you are specifying in your environment configuration. This is unless you are using a dynamic port where you would
specify 0
or -1
as the port.
To start a multi-domain recording session, you would run:
Where <path>
is the path to your saved environment configuration file.
The CLI will then run a proxy server for each of the services you have configured, bound to http://localhost:<port>
where the port is the port you specified in the configuration file. Requests to those endpoints will be proxied to the
endpoint you want to record from. When you have finished the journey you want to record, press <enter>
to save the
stubs to your Mock API in WireMock Cloud and the CLI will exit.
Advanced Recording
The WireMock CLI accepts a configuration file to control how stubs are recorded:
The format of this file is documented in the advanced recording configuration page.
Recording with Mutual TLS
If you need to record from an API that authenticates clients with mutual TLS, the CLI can present your private client certificate in one of two ways:
Via a PEM file
If you have a file containing a PEM encoded RSA private key and X509 certificate, you can provide it as so:
A PEM encoded file should look something like this:
Using a PKCS 12 certificate store
Keeping a private key in PEM format is a security risk, so we also support supplying your client certificate in a password protected PKCS 12 store as so:
You will be challenged for a password to decrypt the store and the private key. The same password must be able to decrypt both.