Skip to navigation

Deploy a mock as a mock server in Postman

View as Markdown

Deploy a mock as a mock server to run its JavaScript request handlers in the Postman Cloud. Unlike a local mock that you start and stop manually, a deployed mock server is always running, so anyone with access can send requests to it at any time.

Deploying a mock as a mock server is supported in Cloud View for Solo, Team, and Enterprise plans only. For more information, see the pricing page.

Deploy a mock as a mock server

  1. Click the Items icon Items tab in the sidebar.
  2. Click Mocks.
  3. Select the mock.
  4. In the upper right, click Deploy. You can also select Options icon View more actions > Deploy next to a mock in the sidebar.
  5. (Optional) Customize the URL for your mock server. The customized URL must be unique and can only have lowercase letters, numbers, and hyphens.
  6. (Optional) Select the Allow public access checkbox to allow anyone with the mock server URL to send requests to it. To learn more, see Make a mock server public.
  7. (Optional) By default, mock servers maintain separate state for each session. To share a single state store across all requests, clear the Enable sessions checkbox. To learn more, see State sessions.
  8. (Optional) Select Auto deploy when mock changes to automatically redeploy the mock server when you make changes to the mock.
  9. Click Deploy.

The mock server is automatically running once it’s deployed.

You can also deploy a mock from the Postman CLI: postman mock push uploads the mock to the Postman Cloud, and postman mock deploy publishes it as a mock server.

To serve several mocks together behind one address, add them to a simulation instead.

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.

To allow anyone with the mock server URL to send requests to it, select Allow public access when deploying 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.

State sessions

By default, mock servers maintain a separate state store for each session when using pm.state. When you clear Enable sessions, all requests share a single state store instead.

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.

Configure a deployed mock server

You can change a deployed mock server’s settings at any time.

  1. Click the Services icon Services tab in the sidebar.

  2. Click Mock Servers.

  3. Select the mock server you want to configure.

  4. In the upper right, select Options icon View more actions > Edit.

  5. Update the mock server’s settings:

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

Call a deployed mock server

After you deploy a mock as a mock server, send requests to the mock server URL to validate that it behaves as expected. The mock server listens for incoming requests and returns responses based on the logic you defined in the mock.

  1. Click the Services icon Services tab in the sidebar.

  2. Click Mock Servers.

  3. Select the mock server.

  4. In the upper right, click Open in Postman icon Open in a new request to open a new request with the URL auto-filled. You can also click Copy icon Copy URL to copy the URL and use it in an HTTP request.

  5. Send requests to the URL and observe the responses.

    • If the mock server is private, you must either be signed in to Postman with access to the workspace, or include a valid x-api-key header with a Postman API key.
    • If the mock server is public, anyone with the mock server URL can send requests to it.

Inspect a deployed mock server

View the requests, responses, and state for a deployed mock server in the Logs and State tabs, the same way you inspect a local mock.

  1. Click the Services icon Services tab in the sidebar, click Mock Servers, then select the mock server.
  2. Use the Session dropdown list to inspect a specific state session.
  3. Use the Logs and State tabs to inspect requests, responses, and state information.

You can also browse a deployed mock server’s request history from the Postman CLI with the postman mock log command.