Setting Up a Mock Server
To set up a mock server in Postman, we will need a collection because mocks in Postman are tied with a collection. Postman compares the requests and creates mock responses from the examples in the requests of a collection.
Before creating a Mock server in Postman, there are some important points about the mock server we must know:
In Postman, there are many ways to build a mock server:
By default, the mocks are open to using. It is accessible publicly. When you make a private mock server, enterprise users and postman pro clients can share the underlying collection with their group and particular team members, or they can give permissions to edit or view.
Let's create the mock server. Here we will discuss how to create a mock server with the New button.
In the above image, we have multiple options.
Fill the column as given below:
In the above image, you can see one checkbox. If you want to make your mock server private, enable it.
Select the Create Mock Server button.
This screen will also display an URL through which we can access the mock server.
Once you close the panel, a new collection has been generated with the given APIs.
Select this environment variable.
Here, you can see, we got the same response body and the same response code as we have created while setting up the mock server.