If the API you’re mocking already exists you can speed up the process of stubbing responses using WireMock Cloud’s record feature. This essentially involves telling WireMock Cloud to act as a proxy to the target API then directing some HTTP requests to WireMock Cloud representing the resources you’d like to stub.
A simple recording example
Once you have logged into WireMock Cloud and created a mock API, navigate to the Stubs page.
Then hit the button, enter
http://ip-api.com as the target URL and hit .
Now make a request to your mock API (substituting
my-mock-api for your own sub domain name):
$ curl -v http://my-mock-api.wiremockapi.cloud/json
This request will be proxied through WireMock Cloud, so that a
GET request will be made to
http://ip-api.com/json and the result captured.
Now hit , and you should see that an extra stub has been added to the list.
Request matching rules when recording
When a request with no body is received during recording, the recorder will create a stub matched on HTTP method and URL only.
When a request with a body is received a body pattern is also included. If the request body is a valid JSON document, then the
equalToJson operator will be used. If XML, the
equalToXml operator will be used. Otherwise the operator will be
equalTo i.e. simple string equality.