> This page is for Postman Docs, version Latest (v12) (default).
> For other versions, use one of these documentation indexes:
> - Latest (v12) (default): https://learning.postman.com/latest-v-12/llms.txt
> - v11: https://learning.postman.com/v11/llms.txt

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt.

# Create a mock server from a collection in Postman

> Create a mock server from the saved examples in a collection, call it, configure response matching, and view its call log.

Create a mock server from the saved [examples](/docs/use/send-requests/response-data/examples/) in a collection. When you send a request, Postman uses a [matching algorithm](/docs/design-apis/mock-apis/mock-servers/matching-algorithm) to return the closest example's response. This is the no-code path to a mock server, useful when you already have a collection of requests and example responses. For a step-by-step walkthrough, see the [collection-based mock server tutorials](/docs/design-apis/mock-apis/tutorials/overview).

> **Info**
>
> Postman mock servers support collections that contain HTTP requests only. You can't use a mock server with a collection that contains a non-HTTP request.

## Create a mock server from a collection \[#create-a-mock-server-from-a-collection]

1. In the sidebar, click ![Add icon](https://assets.postman.com/postman-docs/aether-icons/v12/icon-action-add-stroke.svg#icon) and select **Mock Server**.

2. Select **Existing collection**.

3. Configure your mock server details:

   * **Name** — Enter a name for your mock server.
   * **Collection** — The collection used for the mock server. Specify an existing collection, or select ![Add icon](https://assets.postman.com/postman-docs/aether-icons/v12/icon-action-add-stroke.svg#icon) **Create collection** to create a new one.
   * **Environment** — (Optional) Select an [environment](/docs/use/send-requests/variables/managing-environments/) to use environment variables with your mock server.
   * **Simulate a fixed network delay** — Select a response delay or enter a custom delay. The mock server waits the specified time before sending the response.
   * **Save the mock server URL as a new environment variable** — Save the mock server URL as a variable in a new environment so you can reference it in your requests.
   * **Make mock server private** — Require a [Postman API key](/docs/reference/postman-api/authentication/) in the request header when sending requests to the mock server. To learn more, see [Make calls to a private mock server](#make-calls-to-a-private-mock-server).

4. Click **Deploy**.

You can identify a mock server in the sidebar by the mock icon ![Mock icon](https://assets.postman.com/postman-docs/aether-icons/v12/icon-entity-mock-stroke.svg#icon).

### Create from request history \[#create-from-request-history]

You can build a collection and mock server from requests in your Postman history.

1. Click the ![History icon](https://assets.postman.com/postman-docs/aether-icons/v12/descriptive-history-stroke.svg#icon) **History** tab in the sidebar.
2. Click ![Options icon](https://assets.postman.com/postman-docs/aether-icons/v12/action-options-stroke.svg#icon) **View more actions** next to a request and select **Mock Request**. You can also mock all requests for a specific date. Postman creates a new collection for the mocked requests.
3. Configure the mock server's name, environment, privacy, network delay, and whether to save the URL as an environment variable.
4. Click **Create Mock Server**.

## Call a mock server deployed from a collection \[#call-a-mock-server-deployed-from-a-collection]

When you send a request to the mock server, Postman uses a [matching algorithm](/docs/design-apis/mock-apis/mock-servers/matching-algorithm) to select the best saved example and return its response. You can provide multiple examples to handle different scenarios, and [generate dynamic responses](/docs/design-apis/mock-apis/mock-servers/generate-dynamic-responses) with variables and templates.

1. Click the ![Services icon](https://assets.postman.com/postman-docs/aether-icons/v12/descriptive-services-stroke.svg#icon) **Services** tab in the sidebar, then expand **Mock Servers**.

2. Select the mock server, then click ![Copy icon](https://assets.postman.com/postman-docs/aether-icons/v12/action-copy-stroke.svg#icon) **Copy Mock Server URL**.

3. Open a new request and enter the mock server's URL, including the path to the request you want to mock. For example, `https://4bb57fc2-219e-421e-86b4-4ffda6bf1b3b.mock.pstmn.io/get`.

   > **Info**
   >
   > Make sure the request you want to mock has at least one saved example. Learn more about [adding examples to a request](/docs/use/send-requests/response-data/examples/#add-an-example).

4. If the mock server is private, add your [Postman API key](/docs/reference/postman-api/authentication/) to the request as an `x-api-key` header.

5. Click **Send**.

If you configured a delay for your mock server, Postman waits the specified period of time before sending the response.

### Make calls to a private mock server \[#make-calls-to-a-private-mock-server]

To make calls to a private mock server, add a [Postman API key](/docs/reference/postman-api/authentication/) in the request header (for example, `x-api-key:<Your-Postman-API-key>`). If you [share the collection](/docs/collaborating-in-postman/sharing/), others can use their own Postman API keys to make calls to the mock server.

### Use HTTP access control for a mock server \[#use-http-access-control-for-a-mock-server]

In addition to calling mock endpoints from Postman, you can make requests to a mock server from a web browser. [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is enabled for Postman mock servers, so you can stub your web apps with mocked data. Development or production web apps can make requests to your Postman mock endpoint and receive example responses.

## Configure a collection mock server \[#configure-a-collection-mock-server]

You can change the configuration for a mock server at any time.

1. Click the ![Services icon](https://assets.postman.com/postman-docs/aether-icons/v12/descriptive-services-stroke.svg#icon) **Services** tab in the sidebar, then expand **Mock Servers**.

2. Select a mock server and click ![Setting icon](https://assets.postman.com/postman-docs/aether-icons/v12/descriptive-setting-stroke.svg#icon) **Edit Configuration**.

3. Change the mock server's name, environment, network delay, or privacy setting. You can also [specify options for response matching](#match-request-body-and-headers).

   > **Info**
   >
   > You can't change the mock server's collection. To mock a different collection, create a new mock server.

4. Click **Update Mock Server**.

### Match request body and headers \[#match-request-body-and-headers]

By default, the matching algorithm doesn't consider the request's body or headers when selecting the best response. You can change this in the mock server's configuration to specify the exact response you want by matching the body or headers of the saved example.

1. Click the ![Services icon](https://assets.postman.com/postman-docs/aether-icons/v12/descriptive-services-stroke.svg#icon) **Services** tab in the sidebar, click **Mock Servers**, select a mock server, then click ![Setting icon](https://assets.postman.com/postman-docs/aether-icons/v12/descriptive-setting-stroke.svg#icon) **Edit Configuration**.

2. Under **Response Matching**, select the matching options you want to use:

   * **Request body** — The mock server matches the request's body to the body of the saved examples.
   * **Headers** — The mock server matches the request's headers to the headers of the saved examples. Add a comma-separated list of the header keys to match. Header matching isn't case-sensitive.

3. Click **Update Mock Server**.

> **Info**
>
> If you enable request body matching, you must add the `Content-Type` header to your examples and use the same value as your request, such as `application/json`. To learn how matching works, see [How a Postman mock server matches requests to saved examples](/docs/design-apis/mock-apis/mock-servers/matching-algorithm).

### Delete a mock server \[#delete-a-mock-server]

To delete a mock server, click the ![Services icon](https://assets.postman.com/postman-docs/aether-icons/v12/descriptive-services-stroke.svg#icon) **Services** tab in the sidebar and choose **Mock Servers**, then click ![Options icon](https://assets.postman.com/postman-docs/aether-icons/v12/action-options-stroke.svg#icon) **View more actions** next to the mock server's name and click **Delete**.

## View the call log \[#view-the-call-log]

View and search the details of calls to your mock server using the call log. To view the call log, expand **Mock Servers** in the ![Services icon](https://assets.postman.com/postman-docs/aether-icons/v12/descriptive-services-stroke.svg#icon) **Services** tab and select a mock server.

The call log displays a list of calls made to the mock server URL. Each entry shows the time the request was sent, the request method and path, and a response overview. With the call log, you can:

* Enter text in the search box to find specific requests.
* Click ![Refresh icon](https://assets.postman.com/postman-docs/aether-icons/v12/action-refresh-stroke.svg#icon) **Refresh Logs** to view the most recent requests.
* Select an entry for more details about the request and response headers and body.
* Click ![Copy icon](https://assets.postman.com/postman-docs/aether-icons/v12/action-copy-stroke.svg#icon) **Copy Mock Server URL** to copy the mock server's URL.

### Troubleshoot mock calls \[#troubleshoot-mock-calls]

Use the call log to troubleshoot your requests to mock servers.

If `No matching requests` displays in the **Response** column, there might be a problem with your mock server configuration. Make sure there's an [example saved for the request](/docs/use/send-requests/response-data/examples/#save-a-response-as-an-example) in the collection you're mocking.

In the case of a service outage, you'll get an HTTP 502, 503, or 504 response. Check the Postman [status page](https://status.postman.com/) for updates.