• Home
  • Blog
  • API testing – Postman for beginners

TECHNOLOGIES

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.

Api_testing_postman_for_beginners_rst

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.

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

 

 

 

 

Article notes

Udostępnij

Arkadiusz Kwiatkowski-RST Software

Arkadiusz Kwiatkowski

Software Tester

Graduate of the Military University of Land Forces and the “Horyzont” University of Applied Computing in Wrocław. What he loves the most about his work is the opportunity to grow, as well as the feeling that he’s at the right place and his work is meaningful. Owns Luna, a French bulldog (with visible symptoms of ADHD). Loves to travel and take in the moments when he can rest and feel at one with nature. He’s always smiling and always stays positive. It’s hard to get bored around him.

Newsletter

Newsletter

Thank you!
Your email has been sent.

Our website uses cookies to work correctly. Using this website with current settings means that cookies will be stored in the browser’s memory. Cookies settings can be changed in the browser’s options. For more information please visit Cookies policy.