How to get the response in different format in Mock Server using Postman?


We can get the Response in different formats in Mock Server. A Mock Server is created to avoid sending requests on the real time or production data. The steps to create a Response in different format in Mock Server are listed below −

Step 1 − Click on New from the top of the Postman application. Then click on the Mock Server link.

Step 2 − Choose the option GET from the Method field. Add /user/home in the Request Path, 200 in Response Code and the text – This is Postman Tutori in Tutorialspoint in the Response Body field.

Step 3 − Provide a name to the Mock Server. Then click on Create Mock Server.

Step 4 − The Mock Server is created with the Mock URL. To copy the Mock URL the Copy Mock URL button should be clicked. Click on Close and Proceed.

Step 5 − Choose the Mock Server as the Environment and send a request. The Response Body – This is Postman Tutori in Tutorialspoint is displayed in HTML format.

Step 6 − To get Response in JSON format, we have to select the option Save as Example from the Save Response dropdown.

Step 7 − Enter an Example name and choose JSON from the Response Body.

Step 8 − Incorporate the below Response Body in JSON format and click on the Save Example button.

{
   "name": "Tutorialspoint",
   "subject": "Postman"
}

Step 9 − Execute a GET request and we shall obtain the Response Body in JSON format as we added in the Example request in the Step 8.

The below image shows Response is in HTML format.

The below image shows Response is in JSON format.

Updated on: 03-Aug-2021

626 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements