Arkadiusz Kwiatkowski
Software Tester Lead
Reviewed by a tech expert

API testing: Postman for beginners

#Sales
#Sales
#Sales
#Sales
Read this articles in:
EN
PL

Have you heard people talking about the Postman, and wondered what’s it all about? How to use it?

If you’re looking for answers to these questions, you’re in the right place. This article explains how to use Postman to streamline API tests.

Installation and basic information

The latest version of the tool can be downloaded from: https://www.getpostman.com. Look for a version that matches your system and install it. Create an account (all saved requests are synced in the cloud, so you can access them from anywhere and at any time).

Postman Pro offers additional functionalities, such as sharing collections with a team or starting tests on VMs.

However, the basic version should be sufficient for your everyday work.

Creating a developer account

For practice, we’ll use the API of The New York Times http://developer.nytimes.com. As you can probably imagine, most APIs are protected by some kind of authorisation to protect resources from unauthorised access. This is also the case here. The first step is creating a free developer account.

RST_Software_Masters

To do that, after opening the page click the first item, i.e. Request an API key. On the subsequent page, you’ll see info about data required to obtain a developer key.

RST_software_masters

After entering the data, you will receive an e-mail with the key (we’ll get back to this key later in the text). At this stage, it is necessary to read the documentation to know how to use our test API http://developer.nytimes.com/books_api.json#/Documentation/GET/lists.%7Bformat%7D.

Fetching information from the API:

Once you have read the documentation, you can try to create your first GET request in Postman. After logging in, you’ll see the following window:

RST_software_masters

Select the first item on the left. Next, the following window opens:

RST_software_masters

Enter the name, e.g. “A question about the author”. Next, you have to create a collection to store this particular group of requests (e.g. “NYT API”). Select the newly created collection to store your new request.

As per the documentation, the base API address is:

RST_software_masters

Copy the Base URI to Postman and paste it in the Enter request URL field:

RST_software_masters

Replace the current API version with the latest one (v3 at the time of writing this text). From the NYT documentation, you can see that it’s possible to send requests related to historical data on the best-selling books (the "lists/best-sellers/history.json” resource).

To execute such a request, you need to provide additional information that will be used to narrow down the results. In this example, we will use a narrowing filter by entering a question about the author of a book, e.g. Stephen King, so our request should look like this:

http://api.nytimes.com/svc/books/v3/lists/best-sellers/history.json?author=stephen king

It is also obligatory to pass your key to the Headers tab. In the Key column, enter the api-key value, and in the Value column, enter the value of the key sent to the e-mail you have provided at signing up.

RST_software_masters

After populating the data required for submitting a request, click the Send button.

If during this process you receive a JSON object with a “200” status code and a list that includes Stephen King, that means you just managed to send your first working request with Postman. CONGRATULATIONS!

RST_software_masters

Notice the orange dot in the upper left corner:

RST_software_masters

It indicates that the changes you’ve made to the first template were not saved. After you click on Save, your template will be saved, making it easily accessible at any time.

Automated script

Other than sending requests to the API, you can also use the Tests tab in Postman. This tab lets you input scripts using JavaScript. With that, you can e.g. test your response received from the API. Let’s perform a simple API response test, then. Using our previous “Author request”, we introduce a test to the request that will check the response status:

RST_software_masters

Once you’ve introduced a test script and sent a request, you should see a new tab (Test Results) with test condition status (true/false).

Let’s try something more complicated and verify if the response really returns Stephen King’s books:

RST_software_Masters

As we can see, the newly added test was successful because the returned answer contains information about Stephen King's works, and the Test Results tab has updated information about the number of tests in it.

Conclusion

With the ability to enter test scripts, Postman becomes more than a simple tool for creating collections and manually querying the API. The tool, through its features, can allow us to automate service verification. The benefits of introducing automation into our queries will be immediately apparent when performing regression testing. By creating properly designed test scripts, we gain time savings and eliminate the possibility of human error.

People also ask

No items found.
Want more posts from the author?
Read more

Want to read more?

Web

A step-by-step guide to performance testing

Enhance your app's efficiency with our step-by-step guide to performance testing. Learn to optimize speed and reliability.
Web

Post-deployment application performance monitoring

If you're a member of a development team (particularly a tester), this place is perfect for you. At a certain stage of the project, you publish the application.
No results found.
There are no results with this criteria. Try changing your search.
en