Create mock servers in Postman to help with API development and testing. A mock server simulates a real API server by accepting requests and returning responses. By configuring a mock server for your collection and adding examples to your requests, you can simulate the behavior of a real API.
When you send a request to a mock server, Postman matches the request to a saved example in your collection. Postman then responds with the data in the example. To view mock servers in your workspace, click the 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 can enable or prohibit users from creating public mock servers. See Manage mock server privacy to learn more.
Postman mock servers only support HTTP collections. You can’t use mock servers with multi-protocol collections.
You can create a mock server in the following ways:
https://postman-echo.com/get)./get).x-api-key header in the Headers tab.You can build a collection and mock server based on requests from your Postman history.
Some configuration options may be different, depending on the method you used to create the mock server.
To finish creating a mock server, specify the following details:
Mock server 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 to create the mock server.
Add requests — This option is available if you opted to create a new collection. Enter the requests you want to mock. Click to view additional options to add a request body and description to include in the requests.
Environment — (Optional) Select an environment 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.
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.
If the Make mock server private option is unavailable, it may be turned off in Team resources. An Admin or Super Admin can turn it back on.
Click Create Mock Server.
Postman displays the details you need to use the mock server. To get these details at any time, click the Services tab in the sidebar, then expand Mock Servers and select the mock server.
Click Copy Mock Server URL in the workbench to begin making calls to your mock server.
You can change the configuration for a mock server at any time.
Click the Services tab in the sidebar, then expand Mock Servers.
Select a mock server and click Edit Configuration.
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.
You can’t change the mock server’s collection. If you need to mock a different collection, create a new mock server.
When you are done making configuration changes, click Update Mock Server.
When you send a request to the mock server, Postman uses a matching algorithm 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:
Click the Services tab on the sidebar, then click Mock servers, select a mock server, and click Edit Configuration.
Under Response Matching, select the matching options you want to use:
Click Update Mock Server.
To delete a mock server, click the Services tab on the sidebar and choose Mock servers, then click View more actions next to the mock server’s name and click Delete.
To learn more about mock servers, see the following resources: