To analyse the requests that a system makes the proxy can be used to record all requests and their corresponding responses.

Retrieve Recorded Requests

Recorded requests can be retrieved as a list of requests received by the proxy in either JSON or Java code.

HttpRequest[] recordedRequests = new ProxyClient("localhost", 1090)
    .retrieveRecordedRequests(
        request()
    );
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090)
    .retrieveRecordedRequests({})
    .then(
        function (recordedRequests) {
            console.log(JSON.stringify(recordedRequests));
        },
        function (error) {
            console.log(error);
        }
    );
curl -v -X PUT "http://localhost:1090/retrieve?type=REQUESTS"
HttpRequest[] recordedRequests = new ProxyClient("localhost", 1090)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090).retrieveRecordedRequests({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedRequests) {
        console.log(JSON.stringify(recordedRequests));
    },
    function (error) {
        console.log(error);
    }
);
curl -v -X PUT "http://localhost:1090/retrieve?type=REQUESTS" -d '{
    "path": "/some/path",
    "method": "POST"
}'
String recordedRequests = new ProxyClient("localhost", 1090)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JAVA
    );
curl -v -X PUT "http://localhost:1090/retrieve?type=REQUESTS&format=JAVA" -d '{
    "path": "/some/path"
}'
String recordedRequests = new ProxyClient("localhost", 1090)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JSON
    );
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090).retrieveRecordedRequests({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedRequests) {
        console.log(JSON.stringify(recordedRequests));
    },
    function (error) {
        console.log(error);
    }
);
curl -v -X PUT "http://localhost:1090/retrieve?type=REQUESTS&format=JSON" -d '{
    "path": "/some/path"
}'

Retrieve Recorded Expectations

Recorded requests-response pairs can be retrieved as a list of expectations containing the request and response that was proxied in either JSON or Java code.

The list of retrieved expectations can be used to setup expectations in MockServer to support mocking.

Expectation[] recordedExpectations = new ProxyClient("localhost", 1090)
    .retrieveRecordedExpectations(
        request()
    );
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090)
    .retrieveRecordedExpectations({})
    .then(
        function (recordedExpectations) {
            console.log(JSON.stringify(recordedExpectations));
        },
        function (error) {
            console.log(error);
        }
    );
curl -v -X PUT "http://localhost:1090/retrieve?type=RECORDED_EXPECTATIONS"
Expectation[] recordedExpectations = new ProxyClient("localhost", 1090)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090).retrieveRecordedExpectations({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedExpectations) {
        console.log(JSON.stringify(recordedExpectations));
    },
    function (error) {
        console.log(error);
    }
);
curl -v -X PUT "http://localhost:1090/retrieve?type=RECORDED_EXPECTATIONS" -d '{
    "path": "/some/path",
    "method": "POST"
}'
String recordedExpectations = new ProxyClient("localhost", 1090)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JAVA
    );
curl -v -X PUT "http://localhost:1090/retrieve?type=RECORDED_EXPECTATIONS&format=JAVA" -d '{
    "path": "/some/path"
}'
String recordedExpectations = new ProxyClient("localhost", 1090)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JSON
    );
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090).retrieveRecordedExpectations({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedExpectations) {
        console.log(JSON.stringify(recordedExpectations));
    },
    function (error) {
        console.log(error);
    }
);
curl -v -X PUT "http://localhost:1090/retrieve?type=RECORDED_EXPECTATIONS&format=JSON" -d '{
    "path": "/some/path"
}'