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

# Quick Start

> Get MockServer running and mock your first HTTP request in under 5 minutes.

This guide walks you through starting MockServer, creating an expectation, making a request, and verifying it was received.

<Steps>
  <Step title="Start MockServer">
    Run MockServer as a Docker container, exposed on port 1080:

    ```bash theme={null}
    docker run -d --rm -p 1080:1080 mockserver/mockserver
    ```

    MockServer is now listening at `http://localhost:1080`. A single port handles both HTTP and HTTPS.

    <Tip>
      If you prefer not to use Docker, see [Running MockServer](/running-mockserver) for other deployment options including the standalone JAR, Maven plugin, npm module, and JUnit integrations.
    </Tip>
  </Step>

  <Step title="Create an expectation">
    An expectation tells MockServer what requests to match and what response to return. Create one using the REST API, the Java client, or the JavaScript client.

    <CodeGroup>
      ```bash curl theme={null}
      curl -s -X PUT http://localhost:1080/mockserver/expectation \
        -H "Content-Type: application/json" \
        -d '{
          "httpRequest": {
            "method": "GET",
            "path": "/api/books"
          },
          "httpResponse": {
            "statusCode": 200,
            "headers": {
              "Content-Type": ["application/json"]
            },
            "body": "[{\"id\": 1, \"title\": \"Effective Java\"}]"
          }
        }'
      ```

      ```java Java theme={null}
      import static org.mockserver.model.HttpRequest.request;
      import static org.mockserver.model.HttpResponse.response;
      import org.mockserver.integration.ClientAndServer;

      ClientAndServer mockServer = ClientAndServer.startClientAndServer(1080);

      mockServer.when(
          request()
              .withMethod("GET")
              .withPath("/api/books")
      ).respond(
          response()
              .withStatusCode(200)
              .withHeader("Content-Type", "application/json")
              .withBody("[{\"id\": 1, \"title\": \"Effective Java\"}]")
      );
      ```

      ```javascript JavaScript theme={null}
      const mockserver = require('mockserver-client').mockServerClient;

      mockserver('localhost', 1080).mockAnyResponse({
        httpRequest: {
          method: 'GET',
          path: '/api/books'
        },
        httpResponse: {
          statusCode: 200,
          headers: { 'Content-Type': ['application/json'] },
          body: '[{"id": 1, "title": "Effective Java"}]'
        }
      });
      ```
    </CodeGroup>

    MockServer responds with `201 Created` when the expectation is registered successfully.
  </Step>

  <Step title="Make a request to the mock">
    Send a request to MockServer on the path you configured:

    ```bash theme={null}
    curl -s http://localhost:1080/api/books
    ```

    MockServer matches the request against your expectation and returns the configured response:

    ```json theme={null}
    [{"id": 1, "title": "Effective Java"}]
    ```
  </Step>

  <Step title="Verify the request was received">
    After your test runs, verify that MockServer received the expected request. Use the REST API or a client SDK.

    <CodeGroup>
      ```bash curl theme={null}
      curl -s -X PUT http://localhost:1080/mockserver/verify \
        -H "Content-Type: application/json" \
        -d '{
          "httpRequest": {
            "method": "GET",
            "path": "/api/books"
          },
          "times": {
            "atLeast": 1
          }
        }'
      ```

      ```java Java theme={null}
      mockServer.verify(
          request()
              .withMethod("GET")
              .withPath("/api/books"),
          VerificationTimes.atLeast(1)
      );
      ```

      ```javascript JavaScript theme={null}
      mockserver('localhost', 1080).verify({
        method: 'GET',
        path: '/api/books'
      }, 1);
      ```
    </CodeGroup>

    MockServer returns `202 Accepted` if the verification passes, or a `406 Not Acceptable` with a description of what was received if it fails.

    <Note>
      The request log is only captured when the log level is `INFO` or more verbose. MockServer defaults to `INFO`, so verification works out of the box.
    </Note>
  </Step>
</Steps>

## Next steps

<CardGroup cols={2}>
  <Card title="Creating expectations" icon="list-check" href="/mocking/expectations">
    Learn all the ways to match requests and define responses, including callbacks and forwarding.
  </Card>

  <Card title="Request matchers" icon="filter" href="/mocking/request-matchers">
    Match on headers, cookies, query parameters, body content, and more.
  </Card>

  <Card title="OpenAPI mocking" icon="file-code" href="/mocking/openapi">
    Auto-generate expectations from an OpenAPI v3 specification.
  </Card>

  <Card title="Verification" icon="circle-check" href="/mocking/verification">
    Assert request sequences and counts after your tests run.
  </Card>
</CardGroup>
