Mocking API calls using Postman
Postman provides an interactive GUI to set up mocks for API calls. Let us now review how to set one up step by step:
- Create or use an existing Postman collection as seen earlier in Chapter 7, Test Automation for APIs.
- Set up a request as shown in Figure A.2. There are two scenarios where we end up mocking an API request:
- The first is when we have a sample response from the API call, but subsequent requests cannot be made to the API. We could save the response as an example in Postman and use it for mocking.
- The other one is when the API call does not exist or we do not have a sample. In this case, we will have to build the response from the scratch. We will be simulating this scenario in our example:
Figure A.2 – Postman request
- The next step is to create the mock server for our request as shown in Figure A.3. This can be done by using the Mock Servers option on the left-hand pane and selecting the collection...