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 versions:

 

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.4.1/mockServerClient.js"></script>
 
HttpRequest[] recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
HttpRequest[] recordedRequests = new ClientAndServer(1080)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .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.4.1/mockServerClient.js"></script>
<script>
  mockServerClient("localhost", 1080)
    .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:1080/retrieve?type=REQUESTS" -d '{
    "path": "/some/path",
    "method": "POST"
}'
Expectation[] recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
Expectation[] recordedExpectations = new ClientAndServer(1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .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.4.1/mockServerClient.js"></script>
<script>
  mockServerClient("localhost", 1080)
    .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:1080/retrieve?type=REQUESTS" -d '{
    "path": "/some/path",
    "method": "POST"
}'
HttpRequest[] recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .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.4.1/mockServerClient.js"></script>
<script>
  mockServerClient("localhost", 1080)
    .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:1080/retrieve?type=LOGS" -d '{
    "path": "/some/path",
    "method": "POST"
}'
new MockServerClient("localhost", 1080)
    .verify(
        request()
            .withPath("/some/path"),
        VerificationTimes.atLeast(2)
    );
new ClientAndServer(1080)
    .verify(
        request()
            .withPath("/some/path"),
        VerificationTimes.atLeast(2)
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .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.4.1/mockServerClient.js"></script>
<script>
  mockServerClient("localhost", 1080)
    .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:1080/verify" -d '{
    "httpRequest": {
        "path": "/simple"
    },
    "times": {
        "atLeast": 2,
        "atMost": 2
    }
}'
new MockServerClient("localhost", 1080)
    .verify(
        request()
            .withPath("/some/path/one"),
        request()
            .withPath("/some/path/two"),
        request()
            .withPath("/some/path/three")
    );
new ClientAndServer(1080)
    .verify(
        request()
            .withPath("/some/path/one"),
        request()
            .withPath("/some/path/two"),
        request()
            .withPath("/some/path/three")
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .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.4.1/mockServerClient.js"></script>
<script>
  mockServerClient("localhost", 1080)
    .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:1080/verifySequence" -d '[
    {
      "path": "/some/path/one"
    },
    {
      "path": "/some/path/two"
    },
    {
      "path": "/some/path/three"
    }
]'
new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST")
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .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.4.1/mockServerClient.js"></script>
<script>
  mockServerClient("localhost", 1080)
    .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:1080/clear" -d '{
    "path": "/some/path"
}'
new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST"),
    ClearType.LOG
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .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.4.1/mockServerClient.js"></script>
<script>
  mockServerClient("localhost", 1080)
    .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:1080/clear?type=LOGS" -d '{
    "path": "/some/path"
}'
new MockServerClient("localhost", 1080).reset();
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .reset()
  .then(
    function () {
      console.log("reset all state");
    },
    function (error) {
      console.log(error);
    }
  );
<script src="https://rawgit.com/jamesdbloom/mockserver-client-node/mockserver-5.4.1/mockServerClient.js"></script>
<script>
  mockServerClient("localhost", 1080)
    .reset()
    .then(
      function () {
        console.log("reset all state");
      },
      function (error) {
        console.log(error);
      }
    );
</script>
curl -v -X PUT "http://localhost:1080/reset
List>nteger< boundPorts = new MockServerClient("localhost", 1080).bind(
            0
        );
curl -v -X PUT "http://localhost:1080/bind -d '{
    "ports": [
        0,
        0
    ]
}'
List>nteger< boundPorts = new MockServerClient("localhost", 1080).bind(
            1081, 1082
        );
curl -v -X PUT "http://localhost:1080/bind -d '{
    "ports": [
        1081,
        1082
    ]
}'