Postman: Setting up mock servers

Profile picture for user arilio666

Mock server in postman is handy. We can automate all our APIs even if the backend server is not ready. The developers from the front end can develop even without the backend server is ready.

That is the beauty of a mock server. It helps in speeding the development process and, in turn, helps in speeding up the automation process.

This sounds awesome as it is done totally without any backend server available and is easy to automate and develop.

Let us take a look step by step at how we can set up a mock server:

  • So when that is done, go to your collection and click on the mock collection.

  • It will take us to this page.
  • Provide your very own mock server name.
  • Leave anything other than that default.
  • Hit on create mock server.

  • We can see that our mock server has been created and when that happens, copy the base URL of the mock when it displays after creation.

  • Now let us go to collection and add a new request.
  • Paste in the base mock URL.
  • We can mention /get at the end of the URL just for the mock example.

  • Name the request and save it to our created collection.

  • Now click on the three dots.
  • And hit add example.

  • Let us say we are gonna want a successful mock response.
  • We will name it 200.
  • And we will add the JSON response body as a success message and set the status code to 200 OK.
  • This will mock this example response as 200 OK with message success.

  • So this when we run the URL with the mock example set, we now get the response we assigned to that example.

  • When we run the same mock URL on a browser, we get the status code 200 OK with our simulated response.

In this way, we can set up our own mock server and start working on various simulated scenarios.