Series: So You Want To Learn API Testing?
Part 1: Fundamentals
About Me
My name is Matt Gilbert and I have been in the Software Testing field for close to 10 years now. I have my B.S. in Software Development from Western Governors University. I’ve had the opportunity to take on many different roles in varying industries like Insurance, SaaS, Healthcare, as well as contract work. Across these different industries, I also gained experience with several different testing techniques, which we will discuss in a later publication. These include API testing, Integration, Performance, Accessibility, UI, Usability, Mobile, Contract, as well as automation framework development in Java, C#, Typescript, and Python. You can find me on LinkedIn. Let’s connect!
What is an API?
API stands for Application Programming Interface. It is the backbone of many modern web and mobile applications.
We will be talking about REST APIs since those are the most popular and flexible APIs found on the web today. The client sends requests to the server as data (a request). The server uses this client input to execute internal functions and returns output data back to the client, usually represented in JSON format (more about JSON later).
REST stands for Representational State Transfer. REST defines a set of functions like GET, PUT, HEAD, POST, PATCH, CONNECT, TRACE, OPTIONS & DELETE, that clients can use to access server data.
The main feature of REST API is statelessness. Statelessness means that servers do not save client data between requests. The response from the server is plain data.
Have you ever booked a reservation at a restaurant, ordered food online, or searched for some clothing items at an online store? If so, there is a good chance that you were using an API without even realizing it!
What is JSON? (Simple example)
JSON stands for JavaScript Object Notation. As the name implies, you must think that you can only use JSON when writing JavaScript. This is not the case. While JSON was derived from JavaScript, many of the modern programming languages include code to generate and parse JSON.
What does it mean to “Parse” JSON?
Let’s look at the below code snippet. We can see the variable named jsonData is assigned a value that is some raw JSON. What “parsing” does, simply, is it allows us to get the data that we care about from the JSON. Lines 5 and 8 below are logging the output to the console.
On line 5, obj.count grabs the value of 42 from our JSON.
Line 8 is grabbing obj.result, which is true.
1. const jsonData = '{"result":true, "count":42}';
2. const obj = JSON.parse(jsonData);
3.
4. // expected output: 42
5. console.log(obj.count);
6.
7. // expected output: true
8. console.log(obj.result);What is JSON? (Detailed example)
The above is a simple example. The JSON that you will see represented usually in your applications sometimes goes a lot deeper and has multiple objects with arrays (and sometimes, arrays within arrays).
Below is a more detailed example (using PokeAPI).
{
"count": 1126,
"next": "https://pokeapi.co/api/v2/pokemon?offset=203&limit=3",
"previous": "https://pokeapi.co/api/v2/pokemon?offset=197&limit=3",
"results": [
{
"name": "unown",
"url": "https://pokeapi.co/api/v2/pokemon/201/"
},
{
"name": "wobbuffet",
"url": "https://pokeapi.co/api/v2/pokemon/202/"
},
{
"name": "girafarig",
"url": "https://pokeapi.co/api/v2/pokemon/203/"
}
]
}How would we go about grabbing the “name” of the 2nd Pokemon in the list?
const jsonData = JSON.parse(responseBody);
jsonData.results[1].name;You might be a bit confused at this point so let’s break this down.
jsonData.results – remember the first example above? This should look familiar to you at this point.
What is [1] in the above example??
In the JSON response below, the results are an Array, meaning, a list of items. [ ] is used to symbolize an array.
Okay…that makes sense. Now what about the number 1 within the Array?!
One interesting thing about Arrays is that they always start at 0. If we were to plug in jsonData.results[2].name); into the above code (as you might have guessed to get the 2nd Pokemon), we would actually get back the name of the 3rd Pokemon. Just another thing to remember when working with arrays!
Why are APIs so important?
According to the State of API Integration Report of 2020, 84% of participants find API integration “critical” to their businesses and IT infrastructures. This is a huge number, and I imagine that number is even higher in 2022, with more and more people working from home, shopping online, etc.
Imagine if your favorite Pizza restaurant’s online portal was down and you had to pick up the phone to call and place the order? Hassle. What if your favorite clothing site was unable to return any results for some clothing items you wanted? Annoying. Both these situations lead to lost revenue, and potentially a lost customer. This is not the scenario any business wants to see.
APIs make our lives much easier, as you are probably aware, but if they ever go down or fail to perform how they should, they are extremely frustrating, both for the end-user and the business. Therefore, we must understand how APIs work, how to test them correctly, and how to monitor them, which we will dive further into later on in this series of articles!
Outro
Thanks for reading! Hopefully, this was a good primer to get your feet wet into the world of APIs, what they are & why they are so important to us!
Keep on the lookout for my next article!

