- Download the Postman app from the following link and set up the application.
- Create an account on the site.
After installing the application and creating an account you should get a screen like this:
Don’t forget to login to your account on the application after installing it.
Setting Up a Mock Server
So, click the new button and you get the above screen. Click on mock server and you get the following screen:
Here, you can create a new API to mock or you can mock an existing collection. If you want to know what collections are, check them out here. In the above image you can build your REST API request with its respective HTTP Method. You also get to set your path/endpoint, the response code and the response body for it. You get something like this on completing those steps:
Click on Next and you then have to name the mock server and set any environment variable if needed. These environmental variables are not important now, so set them to No Environment. So now you get something like this:
Click on Next and your Mock Server is setup. You get a mock URL which links to the mock server built by postman. They always end with mock.pstmn.io. You can get the resulting data of your API by hitting that mock URL with the endpoint you made before.
As soon as you close the above page, you find that a new collection has been created with your respective APIs and an environment variable has also been created with the URL equal to the mock URL of your server.
On opening the endpoint we created, you need to setup the environment variable as show in the below image. This then setups Postman to accept the URL from the environment variables and that URL has been mapped to the URL of our mock server.
Now when you click Send you get the below response which is what we had mocked earlier:
Congrats! You Have Just Created a Mock Server in Less Than 5 Minutes.
Now, you can manipulate and get your response as a JSON ,set up multiple API endpoints to handle specific responses and errors etc. Do go through the additional material provided below to explore building more sophisticated and better mock servers.