MockServer Proxy can be controlled in the following ways:

The following activities are supported:

 

REST API

The REST API is documented using Open API specification

 

Java Client

The Java client has the following version:

 

JavaScript Client

The JavaScript client has the following version:

To include the browser based client in an HTML page as follows:

<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.2.3/proxyClient.js"></script>
 
HttpRequest[] recordedRequests = new ProxyClient("localhost", 1090)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
HttpRequest[] recordedRequests = new ClientAndProxy(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);
    }
  );
<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.2.3/proxyClient.js"></script>
<script>
  proxyClient("localhost", 1090)
    .retrieveRecordedRequests({
      "path": "/some/path",
      "method": "POST"
    })
    .then(
      function (recordedRequests) {
        console.log(JSON.stringify(recordedRequests));
      },
      function (error) {
        console.log(error);
      }
    );
</script>
curl -v -X PUT "http://localhost:1090/retrieve?type=REQUESTS" -d '{
    "path": "/some/path",
    "method": "POST"
}'
Expectation[] recordedExpectations = new ProxyClient("localhost", 1090)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
Expectation[] recordedExpectations = new ClientAndProxy(1090)
    .retrieveRecordedExpectations(
        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);
    }
  );
<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.2.3/proxyClient.js"></script>
<script>
  proxyClient("localhost", 1090)
    .retrieveRecordedRequests({
      "path": "/some/path",
      "method": "POST"
    })
    .then(
      function (recordedRequests) {
        console.log(JSON.stringify(recordedRequests));
      },
      function (error) {
        console.log(error);
      }
    );
</script>
curl -v -X PUT "http://localhost:1090/retrieve?type=REQUESTS" -d '{
    "path": "/some/path",
    "method": "POST"
}'
HttpRequest[] recordedRequests = new ProxyClient("localhost", 1090)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090)
  .retrieveLogMessages({
    "path": "/some/path",
    "method": "POST"
  })
  .then(
    function (logMessages) {
      // logMessages is a String[]
      console.log(logMessages);
    },
    function (error) {
      console.log(error);
    }
  );
<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.2.3/proxyClient.js"></script>
<script>
  proxyClient("localhost", 1090)
    .retrieveLogMessages({
      "path": "/some/path",
      "method": "POST"
    })
    .then(
      function (logMessages) {
        // logMessages is a String[]
        console.log(logMessages);
      },
      function (error) {
        console.log(error);
      }
    );
</script>
curl -v -X PUT "http://localhost:1090/retrieve?type=LOGS" -d '{
    "path": "/some/path",
    "method": "POST"
}'
new ProxyClient("localhost", 1090)
    .verify(
        request()
            .withPath("/some/path"),
        VerificationTimes.atLeast(2)
    );
new ClientAndProxy(1090)
    .verify(
        request()
            .withPath("/some/path"),
        VerificationTimes.atLeast(2)
    );
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090)
  .verify(
    {
      'path': '/some/path'
    }, 2, false)
  .then(
    function () {
      console.log("request found exactly 2 times");
    },
    function (error) {
      console.log(error);
    }
  );
<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.2.3/proxyClient.js"></script>
<script>
  proxyClient("localhost", 1090)
    .verify(
      {
        'path': '/some/path'
      }, 2, false)
    .then(
      function () {
        console.log("request found exactly 2 times");
      },
      function (error) {
        console.log(error);
      }
    );
</script>
curl -v -X PUT "http://localhost:1090/verify" -d '{
    "httpRequest": {
        "path": "/simple"
    },
    "times": {
        "count": 2,
        "exact": false
    }
}'
new ProxyClient("localhost", 1090)
    .verify(
        request()
            .withPath("/some/path/one"),
        request()
            .withPath("/some/path/two"),
        request()
            .withPath("/some/path/three")
    );
new ClientAndProxy(1090)
    .verify(
        request()
            .withPath("/some/path/one"),
        request()
            .withPath("/some/path/two"),
        request()
            .withPath("/some/path/three")
    );
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090)
  .verifySequence(
    {
      'path': '/some/path/one'
    },
    {
      'path': '/some/path/two'
    },
    {
      'path': '/some/path/three'
    }
  )
  .then(
    function () {
      console.log("request sequence found in the order specified");
    },
    function (error) {
      console.log(error);
    }
  );
<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.2.3/proxyClient.js"></script>
<script>
  proxyClient("localhost", 1090)
    .verifySequence(
      {
        'path': '/some/path/one'
      },
      {
        'path': '/some/path/two'
      },
      {
        'path': '/some/path/three'
      }
    )
    .then(
      function () {
        console.log("request sequence found in the order specified");
      },
      function (error) {
        console.log(error);
      }
    );
</script>
curl -v -X PUT "http://localhost:1090/verifySequence" -d '[
    {
      "path": "/some/path/one"
    },
    {
      "path": "/some/path/two"
    },
    {
      "path": "/some/path/three"
    }
]'
new ProxyClient("localhost", 1090).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST")
);
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090)
  .clear({
    'path': '/some/path'
  })
  .then(
    function () {
      console.log("cleared state that matches request matcher");
    },
    function (error) {
      console.log(error);
    }
  );
<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.2.3/proxyClient.js"></script>
<script>
  proxyClient("localhost", 1090)
    .clear({
      'path': '/some/path'
    })
    .then(
      function () {
        console.log("cleared state that matches request matcher");
      },
      function (error) {
        console.log(error);
      }
    );
</script>
curl -v -X PUT "http://localhost:1090/clear" -d '{
    "path": "/some/path"
}'
new ProxyClient("localhost", 1090).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST"),
    ClearType.LOG
);
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090)
  .clear({
    'path': '/some/path'
  }, 'LOG')
  .then(
    function () {
      console.log("cleared state that matches request matcher");
    },
    function (error) {
      console.log(error);
    }
  );
<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.2.3/proxyClient.js"></script>
<script>
  proxyClient("localhost", 1090)
    .clear({
      'path': '/some/path'
    }, 'LOG')
    .then(
      function () {
        console.log("cleared state that matches request matcher");
      },
      function (error) {
        console.log(error);
      }
    );
</script>
curl -v -X PUT "http://localhost:1090/clear?type=LOGS" -d '{
    "path": "/some/path"
}'
new ProxyClient("localhost", 1090).reset();
var proxyClient = require('mockserver-client').proxyClient;
proxyClient("localhost", 1090)
  .reset()
  .then(
    function () {
      console.log("reset all state");
    },
    function (error) {
      console.log(error);
    }
  );
<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.2.3/proxyClient.js"></script>
<script>
  proxyClient("localhost", 1090)
    .reset()
    .then(
      function () {
        console.log("reset all state");
      },
      function (error) {
        console.log(error);
      }
    );
</script>
curl -v -X PUT "http://localhost:1090/reset
List>nteger< boundPorts = new ProxyClient("localhost", 1080).bind(
            0
        );
curl -v -X PUT "http://localhost:1080/bind -d '{
    "ports": [
        0,
        0
    ]
}'
List>nteger< boundPorts = new ProxyClient("localhost", 1080).bind(
            1081, 1082
        );
curl -v -X PUT "http://localhost:1080/bind -d '{
    "ports": [
        1081,
        1082
    ]
}'