04.04.2018 - Read in 3 min.
API testing – Postman for beginners
04.04.2018 - Read in 3 min.
Have you heard people talking about the Postman, and wondered what’s it all about? How to use it? This article explains how to use Postman to streamline API tests.
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.
Postman – 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.
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.
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:
Select the first item on the left. Next, the following window opens:
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:
Copy the Base URI to Postman and paste it in the Enter request URL field:
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:
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.
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!
Notice the orange dot in the upper left corner:
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.
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: