Deploy a mock as a mock server in Postman
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
- Click the
Items tab in the sidebar.
- Click Mocks.
- Select the mock.
- In the upper right, click Deploy. You can also select
View more actions > Deploy next to a mock in the sidebar.
- (Optional) Customize the URL for your mock server. The customized URL must be unique and can only have lowercase letters, numbers, and hyphens.
- (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.
- (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.
- (Optional) Select Auto deploy when mock changes to automatically redeploy the mock server when you make changes to the mock.
- 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.
-
Click the
Services tab in the sidebar.
-
Click Mock Servers.
-
Select the mock server you want to configure.
-
In the upper right, select
View more actions > Edit.
-
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.
-
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.
-
Click the
Services tab in the sidebar.
-
Click Mock Servers.
-
Select the mock server.
-
In the upper right, click
Open in a new request to open a new request with the URL auto-filled. You can also click
Copy URL to copy the URL and use it in an HTTP request.
-
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-keyheader with a Postman API key. - If the mock server is public, anyone with the mock server URL can send requests to it.
- If the mock server is private, you must either be signed in to Postman with access to the workspace, or include a valid
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.
- Click the
Services tab in the sidebar, click Mock Servers, then select the mock server.
- Use the Session dropdown list to inspect a specific state session.
- 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.