Author: John Ormerod, W3Partnership Limited
Date: January 2017

Introduction

In part 1 of this series, I covered my experience with:

  • API Definition
  • Unit Testing.

In this (part 2), I cover:

  • Calling APIs: Test Clients

This will be followed by two more:

  • Part 3
    • Function and Load Tests
      • SoapUI
      • JMeter
  • Part 4
    • Mocking back-end services

Some of the tools were recommended by colleagues on projects, some I discovered and the rest were mandated for use on a particular project.

Calling APIs

In this section, we will cover interactive testing using:

  • a browser-based test client
  • GUI-based test ‘drivers’

The difference is that the test clients are interactive debugging aids, whereas ‘drivers’ have their test conditions defined, can be run repeatedly and integrated into a Maven/Jenkins build.

Test Clients

These are particularly useful in the early stages of development to understand the behaviour of APIs that are being invoked by your code. You want to verify the response payload, the http status codes, the http header content for instance. You are also concerned with setting up a call: authorisation credentials, headers and payloads for PUT and POST calls. Once understood, the results of this stage usually find their way into your code where the APIs are being invoked.

Chrome – Postman

This appears to be most popular test client. I haven’t used it very much as I have always found the Chrome browser’s user interface difficult to use, much preferring Firefox (and one of its test clients). However, having used Postman again, for the purpose of writing this document, I could well be about to change my mind!

It is installed as a Chrome App rather than running in the Chrome browser. This means that the user interface is not dictated by Chrome. It has support for adding tabs for additional calls, which makes it is very convenient in use, rather than having to search through multiple ‘anonymous’ tabs in Firefox, just to find an existing test.

Set Credentials

Enter the URL for the call and the action (GET/PUT etc), and the username and password (for basic authorisation)

Press Update Request which creates an Authorization header

Send the Request + Examine the Pesponse

Press Send

The response is shown in the Body tab and the http response code is also shown

The Headers can be displayed in their tab

Useful Features

Open another window

This allows you to keep groups of tabs together in separate windows.

Import API Definitions

You can see RAML and Swagger in the list.

Save calls – in a Collection

Press Save As… so that you can choose a Collection. A Collection enables you to group related calls, which is makes it easy to recall them when you want to resume working in an API.

Firefox – RESTClient

RESTClient is a Firefox add-on, which is installed into Firefox

It is accessed by clicking its icon which has been added to the top line

Set credentials

Press the Authentication twisty and then Basic Authentication

Send the Request + Examine the Response

Useful Features

RESTClient’s facilities for saving and recalling calls is not as rich and convenient as with Postman. To save calls for reuse, it has Favorite Requests. This allows you to save requests by name and export them to the file system.

Conclusion

I hope you have found something of use and interest in how I have shared my experiences of using these tools, and will investigate and use them yourself.