> ## Documentation Index
> Fetch the complete documentation index at: https://moeck.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Verification

> Assert that MockServer received the requests you expected.

MockServer records every request it receives — both requests that matched an expectation and requests that were proxied. Use **verification** to assert after the fact that specific requests arrived, and in what quantity or order.

## Verify a single request

Call `verify` with a request matcher and a `times` condition.

### At least N times

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    new MockServerClient("localhost", 1080)
        .verify(
            request()
                .withPath("/some/path"),
            VerificationTimes.atLeast(2)
        );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    var mockServerClient = require('mockserver-client').mockServerClient;
    mockServerClient("localhost", 1080)
        .verify(
            { 'path': '/some/path' },
            2
        )
        .then(
            function () { console.log("request found at least 2 times"); },
            function (error) { console.log(error); }
        );
    ```
  </Tab>

  <Tab title="REST API">
    ```bash theme={null}
    curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
        "httpRequest": {
            "path": "/some/path"
        },
        "times": {
            "atLeast": 2
        }
    }'
    ```
  </Tab>
</Tabs>

### At most N times

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    new MockServerClient("localhost", 1080)
        .verify(
            request().withPath("/some/path"),
            VerificationTimes.atMost(2)
        );
    ```
  </Tab>

  <Tab title="REST API">
    ```bash theme={null}
    curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
        "httpRequest": { "path": "/some/path" },
        "times": { "atMost": 2 }
    }'
    ```
  </Tab>
</Tabs>

### Exactly N times

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    new MockServerClient("localhost", 1080)
        .verify(
            request().withPath("/some/path"),
            VerificationTimes.exactly(2)
        );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    mockServerClient("localhost", 1080)
        .verify({ 'path': '/some/path' }, 2, 2)
        .then(
            function () { console.log("request found exactly 2 times"); },
            function (error) { console.log(error); }
        );
    ```
  </Tab>

  <Tab title="REST API">
    ```bash theme={null}
    curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
        "httpRequest": { "path": "/some/path" },
        "times": { "atLeast": 2, "atMost": 2 }
    }'
    ```
  </Tab>
</Tabs>

### Never received

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    new MockServerClient("localhost", 1080)
        .verify(
            request().withPath("/some/path"),
            VerificationTimes.exactly(0)
        );
    ```
  </Tab>

  <Tab title="REST API">
    ```bash theme={null}
    curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
        "httpRequest": { "path": "/some/path" },
        "times": { "atMost": 0 }
    }'
    ```
  </Tab>
</Tabs>

## Verify using an OpenAPI matcher

Use an OpenAPI spec as the request matcher in a verification call. This is useful when you want to verify that a request conforming to a specific API operation was received.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    // verify any operation in the spec was called at least twice
    new MockServerClient("localhost", 1080)
        .verify(
            openAPI(
                "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
            ),
            VerificationTimes.atLeast(2)
        );

    // verify a specific operation was called exactly once
    new MockServerClient("localhost", 1080)
        .verify(
            openAPI(
                "org/mockserver/openapi/openapi_petstore_example.json",
                "showPetById"
            ),
            VerificationTimes.once()
        );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    // verify any operation at least twice
    mockServerClient("localhost", 1080)
        .verify(
            {
                'specUrlOrPayload': 'https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json'
            },
            2
        );

    // verify a specific operation exactly once
    mockServerClient("localhost", 1080)
        .verify(
            {
                'specUrlOrPayload': 'org/mockserver/openapi/openapi_petstore_example.json',
                'operationId': 'showPetById'
            },
            1, 1
        );
    ```
  </Tab>

  <Tab title="REST API">
    ```bash theme={null}
    # at least twice
    curl -v -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"
        },
        "times": { "atLeast": 2 }
    }'

    # specific operation exactly once
    curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
        "httpRequest": {
            "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
            "operationId": "showPetById"
        },
        "times": { "atLeast": 1, "atMost": 1 }
    }'
    ```
  </Tab>
</Tabs>

## Verify by expectation ID

If you assigned an `id` to an expectation, you can verify by that ID directly:

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    new MockServerClient("localhost", 1080)
        .verify(
            "31e4ca35-66c6-4645-afeb-6e66c4ca0559",
            VerificationTimes.once()
        );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    mockServerClient("localhost", 1080)
        .verifyById(
            { 'id': '31e4ca35-66c6-4645-afeb-6e66c4ca0559' },
            1, 1
        );
    ```
  </Tab>

  <Tab title="REST API">
    ```bash theme={null}
    curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
        "id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"
    }'
    ```
  </Tab>
</Tabs>

## Verify a sequence of requests

Use `verifySequence` (or pass multiple request matchers to `verify` in Java) to assert that a set of requests arrived **in order**. Each request in the sequence must have been received at least once, and each must have been received after the previous one.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    new MockServerClient("localhost", 1080)
        .verify(
            request().withPath("/some/path/one"),
            request().withPath("/some/path/two"),
            request().withPath("/some/path/three")
        );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    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("sequence found in order"); },
            function (error) { console.log(error); }
        );
    ```
  </Tab>

  <Tab title="REST API">
    ```bash theme={null}
    curl -v -X PUT "http://localhost:1080/mockserver/verifySequence" -d '{
        "httpRequests": [
            { "path": "/some/path/one" },
            { "path": "/some/path/two" },
            { "path": "/some/path/three" }
        ]
    }'
    ```
  </Tab>
</Tabs>

### Mix request matchers and OpenAPI matchers in a sequence

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    new MockServerClient("localhost", 1080)
        .verify(
            request().withPath("/status"),
            openAPI(
                "org/mockserver/openapi/openapi_petstore_example.json",
                "listPets"
            ),
            openAPI(
                "org/mockserver/openapi/openapi_petstore_example.json",
                "showPetById"
            )
        );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    mockServerClient("localhost", 1080)
        .verifySequence(
            { 'path': '/status' },
            {
                'specUrlOrPayload': 'org/mockserver/openapi/openapi_petstore_example.json',
                'operationId': 'listPets'
            },
            {
                'specUrlOrPayload': 'org/mockserver/openapi/openapi_petstore_example.json',
                'operationId': 'showPetById'
            }
        );
    ```
  </Tab>

  <Tab title="REST API">
    ```bash theme={null}
    curl -v -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"
            }
        ]
    }'
    ```
  </Tab>
</Tabs>

## Retrieve recorded requests for debugging

Retrieve all requests MockServer has recorded so you can inspect what arrived:

```bash theme={null}
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS" -d '{
    "httpRequest": {
        "path": "/some/path"
    }
}'
```

Retrieve recorded requests as Java code or JSON:

```bash theme={null}
# as JSON (default)
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS&format=JSON"

# as Java
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS&format=JAVA"
```

Retrieve active expectations (useful for confirming which expectations are still registered):

```bash theme={null}
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=ACTIVE_EXPECTATIONS"
```

<Tip>
  If a verification assertion fails unexpectedly, retrieve recorded requests to see exactly what MockServer received. This can reveal URL encoding differences, unexpected headers, or missing request bodies.
</Tip>
