How to Use Postman for API Testing Dan Martin September 9, 2020 APIs are everywhere on the Internet. Each time you send and receive messages using an instant messaging app, or while checking the news on the Internet, API requests are being requested and received in the background. Some of the HTTP methods associated with APIs are GET, POST, PUT, DELETE, and PATCH.When a developer creates an API, it needs to be tested for its quality. There are many elements that make up modern API testing, from checking functional requirements to the performance, reliability, and security of the service.There are also many popular tools to enable quick API testing, like SoapUI, RapidAPI, and TestProject. Postman is another such tool that can aid an API developer’s testing process. Below, we’ll describe how to use Postman to test the two most common HTTP methods, GET and POST.Organizing Tests in PostmanPostman helps an API developer organize API requests inside Collections. To add a new Collection, click the Collection button in the Workspace. Next, click the Request button to add the request into the collection. Requests can also be further organized within folders.Creating a GET RequestGET is used to request data from a specified resource. Once the new request is chosen as a GET request in the tool, proceed to name the request. Next, mention the URL to be tested.Once the request is saved, send the request by clicking the Send button. As a result, the response body is displayed in the lower section of the Workspace. The response body is the result of the API request being sent. To validate this result of the GET request, view the response text, Status, Time Taken, Size in that section.For example, if the response body is shown as empty, and the status is not labeled as OK, it signifies an issue. Similarly, if the Time Taken label shows an unexpectedly high amount, the API developer may want to check for performance issues.For debugging the test results, the Console Window can be relied upon. Traverse through View>Show Postman Console to use it. For example, below are cases of successful and error requests in the Console Window. Expand and click the Response body section to validate the result for each run. The console window looks as such:Creating a POST RequestPOST is used to send data to a server to create/update a resource. To create a POST request, we follow similar steps as we did for the GET request creation. However, this time choose the POST option for the URL. We also mention the data to be created or updated in the Request Body section. After that, we click the Save button and send the request by clicking the Send button. The response is displayed as a result.Reusing Test Data: Environment and ParameterizationWe can also store the test data inputs by associating it with variables in the Environment section of the Postman App. You can have both local and global variables. To use the data associated with the variables, we mention them within curly braces. This is called Parameterization. The use of the key-value pairs in the Environment allows for the reusability of test data across tests in a Workspace. For example, if we mention the variables in the global environment section, the variable can be referred to across test spaces.Running TestsTo run the tests, choose the Collection and click the Run button. Once that is done, link a data file as an input file if present, else, ignore this step. In the example below, we have not chosen an input file. We have provided direct inputs in this case. Next, click the ‘Run Collection’ button. This runs the test. View the Summary of the results, Export the results and even Rerun the tests from the same window by clicking the respective buttons in the Results window.Enabling Tests to be Data-DrivenTests can be easily made data-driven by associating the test data inputs present in a CSV or JSON file. In the first example, we have shown how we can store the test data in the CSV file and then reference it with the test. We would need to parameterize the variables associated with the CSV file input variables before we do so.In this example, it would be the associated CSV columns. Here, we have the endpoint, email, and password mentioned as column headers in the CSV file. After that, click the Run Collection Button. Once the test is run, view the Console Window to check if the POST request’s response body shows the input that we had provided in the POST request.Similarly, we can have a JSON file as an input and associate the run the tests. Choose the JSON file instead this time, and then run the Collection. View the result in the Response Body to verify if the input matched as was mentioned by us in the JSON file as the test data input file.NewmanNewman is a command-line collection runner for Postman. To use it, we need to install Node.js and Newman into our system. Newman’s input should be the Collection’s JSON file. This can be made available by exporting the Collection and saving it as a JSON file in your local machine. After that, run Newman by associating with that JSON file path. Results are displayed in the command window. Sharing the Collection to Be Run Remotely as a Public URLThe Collection can also be shared as a public URL by choosing the Collection and clicking the ‘Share’ button. The public URL link is automatically built which can be linked-to in the Newman command as ‘Newman run <Public URL link>‘.In ConclusionHence, we’ve learned that the Postman app is a powerful API Testing tool due to the attractive features that it provides. Similarly, other testing tools such as SoapUI, TestProject, etc, which can be used for effective API Testing. SoapUI is a Functional Testing tool for SOAP and REST testing. Testproject is a free automation tool that requires an Add-on called RESTful API Client to test APIs.