Learn How To Use The Postman Tool To Test The API

·

6 min read

This blog will cover how to test the APIs using the Postman tool to simplify the API testing process. Using APIs daily can be difficult because there may be dozens, if not hundreds, of APIs to use or test. That makes it delicate to keep up with their exact requests’ addresses, headers, authorization credentials, etc. And it makes it harder to test the API for functionality, security, and exception handling.

What’s inside this blog:

● What is API testing? ● What is Postman? ● HTTP status codes and descriptions ● The most common HTTP methods ● How to use Postman to test APIs? ● How Postman helps to test Ambee APIs? ● Running a Postman collection.

What is API Testing?

API testing is a type of software testing that validates application programming interfaces (APIs). API testing aims to check the functionality, reliability, performance, and security of the programming interfaces. Instead of standard user inputs(keyboard) and outputs in API testing, you use software to send calls to the API, get output, and note down the system’s response. API tests are very different from GUI tests and won’t concentrate on the look and feel of an application. It mainly focuses on the business logic layer of the software architecture.

Why Postman Tool?

Postman is an application used for API testing. It is an HTTP client that tests HTTP requests, utilizing a graphical user interface, through which we obtain different types of responses that need to be subsequently validated.

HTTP status codes and descriptions

image1.png

Most common HTTP methods:

  1. GET: The GET method retrieves data from a given server using a URI. The GET method is used to retrieve the data. Because of that, no data should be affected.
  2. POST: The POST method sends data to the server to create a resource. For example, user information and file uploads using HTML forms.
  3. PUT: PUT is used to send data to a server to create or update a resource. The difference between POST and PUT is that calling the same PUT request multiple times will always produce the same result. Calling a POST request repeatedly has the side effect of creating the same resource multiple times.
  4. PATCH: The PATCH technique makes partial changes to a resource. For instance, when you only need to change one field in the resource,
  5. HEAD: HEAD is almost identical to GET but without the response body. HEAD transfers the status line and the header segment only.
  6. DELETE: The DELETE method deletes the specified resource.
  7. OPTIONS: The OPTIONS method describes the communication options for the target resource.

How to Use Postman to Test APIs

The Postman is an excellent tool. When it comes to testing and executing APIs, once you have entered the APIs and saved them, you can use them multiple times without needing API keys, endpoints, headers, etc.

Here is an example of how to enter a new API request using Ambee’s air quality APIs. You can also do this for the product you are developing.

‘Create a test case’ for the API; you can also do this for the product you are developing:

Launch the Postman tool by double-clicking on the logo. After it completely loads the main screen, follow these steps to create your collection of requests:

image3.png

1) To add a new collection, click on the "+" button on the "collections" tab. A new collection will be created, and you will be able to edit its name, description, and many other settings.

image2.png

2) Name the collection.

image5.png

image4.png

3) Then right-click on the new collection and select “add request” to create your first request.

image7.png

4) Select the recently created request and enter the API endpoint where it says, "Enter request URL’ and select the method (the action type) on the left of that field. The default method is GET. We are using the same method in the example below.

image6.png

5) Enter Ambee’s air quality API key and enter headers in case they are required.

image9.png

6) Click on the send button and validate the response against the expected result.

image8.png

How Postman helps to test Ambee air quality APIs

One of Postman’s amazing features is "Collections". "Collections" allow you to group together a few APIs that should be executed in a certain sequence.

image12.png

In the above screenshot, you can see the first collection that includes 6 APIs, all of which are required to run the air quality latest and air quality history tests.

There is an pollen forecast API option too, along with many other environmental APIs.

Scenarios that cover

1) Heath check / Positive testing - Check basic functionality and the acceptance criteria of the API. 2) positive testing with optional parameters: Tests to include optional parameters and extra functionality. 3) Negative testing: Expect the API to gracefully handle problem scenarios with both valid and invalid input. 4) Security and authorization test: This test includes API key checks and invalid API key checks. 5) Response validation against actual and expected results.

How to run the collection

The beauty of the collection runner is that you can run and execute any number of APIs in one shot. To run a Postman Collection, you will need to use a feature called ‘Collection Runner’ following this step: 1) In the Postan tool GUI, in the bottom right corner of the screen, there is a button called "Runner". Click on that button

image10.png

2) Drag and drop the collection or folder to the "runner" window that you want to run. In our case, it will be the collection called "Ambee Air Quality API".

image11.png

3) You have the option to define extra configuration parameters. However, this is not mandatory. For instance, you can add delays in between each API request and select the number of iterations you want to run the collection for.

4) Advanced settings

a) Save responses - Save response headers and bodies to the log to review them later. This setting can affect performance for large collection runs.

b) Keep variable values - Persist on the variables used in the run, so that any variables updated by the run will remain changed after it completes. If you don't persist variables, changes aren't saved after the run completes. Note that persisting variables in the collection run will update the current value only.

c) Run collection without using stored cookies - You can choose to disable cookies for a collection run if your requests require them.

d) Save cookies after collection run - Save the cookies used in this session to the cookie manager. Any values affected by requests during the run will remain after it completes.

5) Click on the run - Ambee – Air Quality API to run the collections.

image13.png

View test results

We can add an automation script or test script to the result view. An automation script is used to check if the test cases passed or failed. That we will see in the next blog, "postman automation script."

image14.png

image15.png

Conclusion

API testing helps you to ensure the APIs of the application are robust and quality delivered. A postman is an open-source tool. This tool makes API testing easy and simpler for many QA testers. The Postman tool can save your time and help you achieve your targets well on time.