Recording Stubs

If the API you’re mocking already exists you can speed up the process of stubbing responses using MockLab’s record feature. This essentially involves telling MockLab to act as a proxy to the target API then directing some HTTP requests to MockLab representing the resources you’d like to stub.

A simple recording example

Once you have logged into MockLab and created a mock API, navigate to the Stubs page.

Then hit the button, enter 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

This request will be proxied through MockLab, so that a GET request will be made to 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.