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

# Deploy a mock server

Create a *mock server* in Postman to simulate a real API server that's always available to handle requests. You can create a mock server from a mock or from a collection.

To view mock servers in your workspace, 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**.

Mock servers can be private or public. Private mock servers require a Postman API key in the request header. Public mock servers can receive requests from anyone and anywhere (such as a browser, application code, or a curl command). New mock servers are public by default. [Super Admins and Admins](/docs/administration/roles-and-permissions/#team-roles) can enable or prohibit users from creating public mock servers. See [Manage mock servers](/docs/administration/managing-your-team/manage-team-workspaces/#manage-mock-servers) to learn more.

Postman mock servers support collections that contain HTTP requests only. You can't use mock servers with collections that contain at least one non-HTTP request.

## Create from a mock

Deploy a [mock](/docs/design-apis/mock-apis/local-mock-servers/) as a mock server to run it as an always-available cloud-hosted service. Once deployed, anyone with access can send requests to it at any time.

To create a mock server from an existing mock, do the following:

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 mock**. This is selected by default.

3. Configure your mock server details:

   * **Name** — Enter a name for the mock server.
   * **Mock** — Select a mock that hasn't been deployed as a mock server yet. You can also select ![Add icon](https://assets.postman.com/postman-docs/aether-icons/v12/icon-action-add-stroke.svg#icon) **Create mock** to create a new mock. To learn more, see [Build API mocks with JavaScript](/docs/design-apis/mock-apis/local-mock-servers/).
   * **URL** — (Optional) Customize the URL for your mock server. The customized URL must be unique and can only have lowercase letters, numbers, and hyphens.
   * **Allow public access** — Select this checkbox to allow anyone with the mock server URL to send requests to the mock server. To learn more, see [Allow public access](#make-a-mock-server-public).
   * **Enable sessions** — By default, mock servers maintain separate state for each session. Clear this checkbox to share a single state store across all requests instead. To learn more, see [State sessions](#state-sessions).
   * **Auto deploy when mock changes** — Select this option to automatically redeploy the mock server when you make changes to the mock.

4. Click **Deploy**.

You can also create a mock, start it locally to test it, and then deploy it as a mock server when you're ready. To learn more, see [Build API mocks with JavaScript](/docs/design-apis/mock-apis/local-mock-servers/).

### Make a mock server public

Mock servers deployed from a mock are private by default. Private mock servers can only be accessed by workspace members or callers that include a valid `x-api-key` header with a [Postman API key](/docs/reference/postman-api/authentication#generate-a-postman-api-key).

To allow anyone with the mock server URL to send requests to the mock server, select **Allow public access** when creating or editing the mock server.

On Team and Enterprise plans, your team may require Team Admin approval before a mock server can be made public. If approval is required, your request will be submitted for review and the mock server will remain private until it's approved.

Learn how a Team Admin can [manage whether public mock servers require approval](/docs/administration/managing-your-team/manage-team-workspaces#manage-mock-servers).

### State sessions

By default, all requests to a mock server share the same state store when using `pm.state`. When you enable sessions, each session gets its own isolated copy of state.

Use state sessions to simulate multiple users, run parallel tests, or test stateful workflows without requests affecting each other's data. Identify a session using the `x-mock-session` header. Postman can also use a `pm_mock_session` cookie to maintain a session across requests automatically.

To learn more about `pm.state`, see [Use pm methods in the mock editor](/docs/design-apis/mock-apis/local-mock-servers#use-pm-methods-in-the-mock-editor).

### Configure a deployed mock server

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

2. Click **Mock Servers**.

3. Select the mock server you want to configure.

4. In the upper right of the editor, select ![Options icon](https://assets.postman.com/postman-docs/aether-icons/v12/icon-action-options-stroke.svg#icon) > **Edit configuration**.

5. You can configure the following details:

   * **URL** — The unique URL for the mock server. It can only have lowercase letters, numbers, and hyphens.
   * **Allow public access** — Allow anyone with the mock server URL to send requests to it. On Team and Enterprise plans, this may require Team Admin approval.
   * **Enable sessions** — When turned on, each session gets its own isolated copy of state. When turned off, all requests share a single state store.
   * **Auto deploy when mock changes** — Automatically redeploy the mock server when you make changes to the mock.

6. Click **Save**.

## Create from a collection

Create a mock server from saved examples in a collection to help with API development and testing. When you send a request to the mock server, Postman matches the request to a saved example in your collection and responds with the data in the example.

To create a mock server from an existing collection, do the following:

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. You can specify a collection if you selected 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 collection and add it to the mock server.
   * **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** — Select this option to save the mock server URL as a variable in a new environment. You can then reference the variable in your requests. Learn more about [using variables with mock servers](/docs/design-apis/mock-apis/create-dynamic-responses/#use-postman-variables-with-mock-servers).
   * **Make mock server private** — Select this option to make your mock server private. You must specify an API key in the request header when sending requests to a private mock server. Learn more about [making calls to a private mock server](/docs/design-apis/mock-apis/mock-server-calls/#make-calls-to-a-private-mock-server).

     If the **Make mock server private** option is unavailable, it may be turned off in [Team resources](http://go.postman.co/settings/team/team-resources). An [Admin or Super Admin](/docs/administration/roles-and-permissions/#team-roles) can turn it back on.

4. Click **Deploy**.

   Postman displays the details you need to use the mock server. To get these details at any time, 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** and select the mock server.

5. Click ![Copy icon](https://assets.postman.com/postman-docs/aether-icons/v12/action-copy-stroke.svg#icon) **Copy Mock Server URL** in the workbench to begin [making calls to your mock server](/docs/design-apis/mock-apis/mock-server-calls/).

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).

### Edit the mock server configuration

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. Make any changes to the mock server configuration. You can change the mock server's name, environment, network delay, and privacy setting. You can also [specify options for response matching](#match-request-body-and-headers).

   You can't change the mock server's collection. If you need to mock a different collection, [create a new mock server](#create-from-a-collection).

4. When you are done making configuration changes, click **Update Mock Server**.

### Match request body and headers

When you send a request to the mock server, Postman uses a [matching algorithm](/docs/design-apis/mock-apis/matching-algorithm/#6-check-for-header-and-body-matching) to decide which example to return in a response.

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

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 use body or header matching with a mock server, do the following:

1. Click the Services tab on the sidebar, then click **Mock servers**, select a mock server, and 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. In the box, add a comma-separated list of the header keys that you want the mock server to match. Header matching isn't case-sensitive.

3. Click **Update Mock Server**.

For more advanced request matching and dynamic response logic, use a [mock](/docs/design-apis/mock-apis/local-mock-servers).

### Delete a mock server

To delete a mock server, click the Services tab on 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**.

## Create from history

You can build a collection and mock server based on requests from 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) **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 request or requests.

3. Configure the following details:

   * **Name** — Enter a name for your mock server.
   * **Environment** — (Optional) Select an environment to use environment variables with your mock server.
   * **Make mock server private** — Select this option to make your mock server private. You must specify an API key in the request header when sending requests to a private mock server. Learn more about [making calls to a private mock server](/docs/design-apis/mock-apis/mock-server-calls/#make-calls-to-a-private-mock-server).
   * **Save the mock server URL as a new environment variable** — Select this option to save the mock server URL as a variable in a new environment. Learn more about [using variables with mock servers](/docs/design-apis/mock-apis/create-dynamic-responses/#use-postman-variables-with-mock-servers).
   * **Simulate a fixed network delay** — Select a response delay or enter a custom delay.

4. Click **Create Mock Server**.

To edit the configuration, match request body and headers, or delete the mock server, see [Create from a collection](#create-from-a-collection).

## Next steps

To learn more about mock servers, see the following resources:

* [Make calls to your mock server](/docs/design-apis/mock-apis/mock-server-calls/)
* [Mock APIs with response examples](/docs/design-apis/mock-apis/tutorials/mock-with-examples/)
* [Create and use a mock server using the Postman API](/docs/design-apis/mock-apis/tutorials/mock-with-api/)
* [How a Postman mock server matches requests to saved examples](/docs/design-apis/mock-apis/matching-algorithm/)
* [Build API mocks with JavaScript](/docs/design-apis/mock-apis/local-mock-servers/)