Legacy Documentation
You're viewing legacy documentation for API Fortress (deployed via an on-premises container). To view documentation for the new SaaS version of API Fortress — now known as Sauce Labs API Testing and Monitoring (with Sauce Connect tunnels) — see API Testing on the Sauce Labs Cloud.

Mock Recording Part 3: Recording a Mock Endpoint (Deprecated)

Note: The latest version of Kong is not supported by API Fortress. However, we have now released our own Microgateway that you can use to do mock recording as well as many other features! Click here to download AFtheM and learn more about the features here.

Recording a Mock Endpoint:

Note: As with creating the actual proxied endpoints, creating recorded mocks requires a modification of the DNS. Adding a wildcard entry for the mock server (*.demoapi-mocks.apif.example.com) will allow these requests to be properly routed once the mocks are recorded.

Activate Mock Recording:

The next step is to activate the fotress-http-log plugin for Kong. In order to do so, we must format and send the following request, either through cURL or the HTTP client of your choice:
curl -v -XPOST -d "name=fortress-http-log" -d "config.disable_on_header=x-mock" -d "config.http_endpoint=http://dashboard.apifortress:8080/app/api/rest/v3/1/mocks/push/raw" -d "config.api_key=yourAPIKey" -d "config.secret=yourAPISecret" -d "config.mock_domain=demoapi-mocks.apif.example.com" apif.example.com:8001/apis/3389fcee-3ada-4ed6-957b-082085601111/plugins
Another big HTTP request! Let’s unpack the components therein. Initially, we’re passing a number of url-encoded key/value pairs in the POST body (commonly known as post parameters). These values are largely static.
  • config.api_key: The API Key value created in step 1.
  • config.secret: The API Secret value created in step 1.
  • config.mock_domain: The mock domain you wish these routes to be appended to in API Fortress Mocking. It does not need to already exist.  
The URL we’re actually sending the request to:
apif.example.com:8001/apis/3389fcee-3ada-4ed6-957b-082085601111/plugins
needs to have the first part of the URL (apif.example.com) replaced with the URL of your self-hosted/on-premises API Fortress instance. Once this request has successfully been sent, the fortress-http-log plugin for Kong will be active, and mock recording will be enabled!

Record an Endpoint:

Record a mock by calling the proxied API. Issue the following call from the command line or from the HTTP client of your choosing:
curl -v -H 'key:ABC123' http://proxy-demoapi.apif.example.com:8000/api/retail/product
In this case, we’d be recording the ‘/api/retail/product’ route of our proxied API to the mock domain we configured in the first call (demoapi-mocks.apif.example.com). As always, note that the proxy route in this call must be replaced with the proxy route that you created. Also, note that the port in this case is 8000 rather than 8001.

Query the Recorded Mock API:

Finally, we can verify the new mock route in two primary ways. First, we should now see it in the Mocking interface in API Fortress. Second, we can query the route directly via cURL or the HTTP client of your choosing:
curl -v -H 'x-mock:true' http://proxy-demoapi.apif.example.com:8000/api/retail/product
We should receive the same expected response to this call that we receive when polling either the actual or the proxied API. Note that in this case, the previously required header is no longer explicitly required, and that it’s been replaced with a header that requests the mock endpoint specifically.