Skip to main content
After running your code under test, use the verification endpoints to assert that MockServer received the expected requests. MockServer returns 202 Accepted when verification passes and 406 Not Acceptable (with a descriptive failure message in the response body) when it does not.

PUT /mockserver/verify

Assert that a request matching the given criteria was received a specific number of times. Returns: 202 Accepted if the assertion passes, 406 Not Acceptable with a failure message if it does not.

Request fields

httpRequest
object
required
The request matcher describing the request to check. Supports the same fields as the httpRequest matcher in expectations: method, path, pathParameters, queryStringParameters, headers, cookies, body. You can also match against an OpenAPI operation using specUrlOrPayload and operationId.
times
object
Constraints on how many times the request must have been received. If omitted, MockServer verifies the request was received at least once.
  • atLeast (integer) — the minimum number of times the request must have been received
  • atMost (integer) — the maximum number of times the request may have been received
Omit either field to leave that bound unconstrained.

Verify received at least twice

curl -X PUT "http://localhost:1080/mockserver/verify" \
  -d '{
    "httpRequest": {
      "path": "/some/path"
    },
    "times": {
      "atLeast": 2
    }
  }'

Verify received at most twice

curl -X PUT "http://localhost:1080/mockserver/verify" \
  -d '{
    "httpRequest": {
      "path": "/some/path"
    },
    "times": {
      "atMost": 2
    }
  }'

Verify received exactly twice

Set both atLeast and atMost to the same value:
curl -X PUT "http://localhost:1080/mockserver/verify" \
  -d '{
    "httpRequest": {
      "path": "/some/path"
    },
    "times": {
      "atLeast": 2,
      "atMost": 2
    }
  }'

Verify received at least once (default)

Omit times entirely, or set only atLeast: 1:
curl -X PUT "http://localhost:1080/mockserver/verify" \
  -d '{
    "httpRequest": {
      "path": "/simple"
    },
    "times": {
      "atLeast": 1
    }
  }'

Verify against an OpenAPI operation

curl -X PUT "http://localhost:1080/mockserver/verify" \
  -d '{
    "httpRequest": {
      "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
      "operationId": "showPetById"
    },
    "times": {
      "atLeast": 2,
      "atMost": 2
    }
  }'

Failure response

When verification fails, MockServer returns 406 Not Acceptable. The response body contains a human-readable explanation of what was expected versus what was received, for example:
Request not found at least 2 times, expected:<{
  "method" : "GET",
  "path" : "/some/path"
}> but was:<{
  "method" : "GET",
  "path" : "/other/path"
}>
IntelliJ IDEA can display the diff inline when you use MockServer’s Java client. The REST API returns the same message as plain text.

PUT /mockserver/verifySequence

Assert that a set of requests was received in the specified order. MockServer checks that each request in the array was received, in sequence, with no constraint on what other requests arrived between them. Returns: 202 Accepted if the sequence matched, 406 Not Acceptable with a failure message if it did not.

Request fields

httpRequests
array
required
An ordered array of request matchers. Each element uses the same matcher fields as httpRequest in expectations. MockServer checks that these requests were received in the order given.

Verify a three-step sequence

curl -X PUT "http://localhost:1080/mockserver/verifySequence" \
  -d '{
    "httpRequests": [
      { "path": "/some/path/one" },
      { "path": "/some/path/two" },
      { "path": "/some/path/three" }
    ]
  }'

Verify a sequence mixing path and OpenAPI matchers

curl -X PUT "http://localhost:1080/mockserver/verifySequence" \
  -d '{
    "httpRequests": [
      { "path": "/status" },
      {
        "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
        "operationId": "listPets"
      },
      {
        "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
        "operationId": "showPetById"
      }
    ]
  }'

Verify a sequence by expectation IDs

curl -X PUT "http://localhost:1080/mockserver/verifySequence" \
  -d '{
    "httpRequests": [
      { "id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559" },
      { "id": "66c6ca35-ca35-66f5-8feb-5e6ac7ca0559" },
      { "id": "ca3531e4-23c8-ff45-88f5-4ca0c7ca0559" }
    ]
  }'