Testing a RESTful API using Supertest


This post explains how to test a RESTful API using Supertest.

There are many great blog posts that explain how to test NodeJS Express API’s using Supertest. For example:

This post explains how Supertest can be used to test any RESTful API even those that don’t run through express.


You will need a couple of node packages to get going including:

  • Supertest – “High-level abstraction module for testing HTTP”
  • Mocha – “Mocha is a simple, flexible, fun JavaScript test framework for node.js and the browser”
  • chai – “Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.”

Once installed your package.json should look something like this:

Testing API

To try out Supertest i tested http://postcodes.io/ – Postcode & Geolocation API for the UK

Searching for a single Post Code (GET Method)


In this method the user can query the Post Code data for a single post code. If valid, the API returns further detail.

In the tests below you can see a basic example that calls the API with a given Post Code and then performs assertions on the response. You can see in all three cases i’m checking the Status Code of the response and also inspecting the JSON response to ensure the correct data has been returned.

Searching for multiple Post Codes (POST Method)

To search for multiple Post Codes we need to POST an array of Post Codes to the API. To do this we pass in a JSON object to the service, in this example three post codes.

You can see we are again checking the status code of the response. In addition as multiple post codes are returned we iterate through the response to ensure the results match our search.


Supertest is really easy to use. You can very quickly write a series of tests for your API. Posting data and inspecting responses is very easy.

At this point i haven’t tried with a secure API that requires authentication but the documentation suggests that this shouldn’t be a problem.


Present Moment Coaching


On Thursday 21st April I attended a “Life Coaching” Meet Up called “Present Moment Coaching” hosted above The Engineer Pub in Primrose Hill, London. I wasn’t really sure what to expect but it was an interesting evening.

What happened?

There were around 12 attendees at the Meet Up. A mixture of Professional Coaches, Students studying Coaching and even a fellow Software Tester.

To kick off we went around the group to share “What is coaching to you?”

In my previous blog posts i’ve explained that i’m exploring deeper into my understanding of Coaching so it was good to hear thoughts from a varied group of people. Answers included “Helping unlock an individuals potential”, “Thinking from the heart not mind”, “Not giving advice or your opinion”. During the early discussion we also explored the difference between counselling and coaching which we talked as; Coaching = Looking at the future vs Counselling = Looking at the past.

Present Moment Coaching

Following introductions we did the first exercise.

“In this Meet Up we will learn the art of Present Moment Coaching.  Present Moment Coaching is a a very simple method to help clients  to take back possession of their life as well as being a remarkable and effective way to  self coach.”

In the exercise we all practiced being “Present” for a few minutes. Dan, the meet up organiser talked us though some techniques. Once time was up we shared experiences amongst the group. These included:

  • Became more comfortable with surroundings
  • Focus on your breathing helped
  • Became more aware of body
  • Let things be – e.g Noise in the room. Acceptance.
  • More aware of tiredness
  • Noise of the pub reminded some of their childhood
  • Overhwleming sense of joy and happiness

Coaching in Pairs

Following this exercise we moved onto the second part of the Meet Up where in pairs we had the opportunity to practice coaching and being coached.
This exercise was really valuable. It was good to be able to practice coaching in a safe environment.
My key take aways:
  • My questioning skills in a coaching situation can be improved. I felt i was missing “Powerful Questions”
  • My listening skill has improved recently. I’ve been studying the work of Nancy Kline and this has helped massively.
  • I wasn’t sure when to offer solutions and ideas. Through the discussion after the coaching session we talked that as a coach we should avoid offering solutions.

My first experience of a “Life Coaching” Meet Up was pretty interesting. The opportunity to practice coaching and get other perspectives with other Coaches was really good.

See you at the next Meet Up?

Present Moment Coaching

Thursday, May 26, 2016, 7:00 PM

The Engineer Pub
65, Gloucester Ave, Camden London, NW1 8JH, GB

18 Coaches Attending

The Coaching Exchange is a place to meet and exchange coaching with others.Present Moment Coaching is exploring with your client what is happening for them in the present moment. Often we seek to ignore what is happening now because it means being with our discomfort.Our normal reaction is to judge our discomfort or do something so as we do not fe…

Check out this Meetup →