Beginner-friendly REST API Testing Guide - The Basic Concepts

Do you have any idea what to do when someone asks you to test an API? What questions to ask to help you identify the testing scope? What tools to use? How to write an automation test? What evidence shows that the test has been passed?
In this tutorial, we will cover the basics about REST API and everything you need to know to get started.
You'll find a lot of new words in your journey, don't worry about it, it's going to take some time until it starts to sink in, keep practice, have patience, you'll learn along the way.

We also strongly recommend that you read the reference in this tutorial, it will help you learn better.
This Testing Guide gives you an overall view of how to start, and how everything hangs together. It helps you learn step-by-step, but you can skip steps if you already learn the knowledge somewhere else.

Now: Where do you begin?

You could start by learning The Basic Concepts about ReST API first.

Things like:
  • REST or RESTful APIs
  • Web service
  • HTTP
  • JSON
  • URIs
Let's get started with the first step.

What is an API?

Technically API stands for Application Programming Interface. API allows applications to communicate to each other. Companies built their API for external customers or internal use.
  • Chris Hoffman provides an interesting metaphor in What is an API, that you can think of an API like a menu in a restaurant. You can specify what menu items you want without any need to know exactly how the restaurant prepares the food. 
Here's a couple of references that would help you understand the API concept better. 
What is REST API and RESTful? 
You learned API now, but you also heard of REST API. Are they the same? 

In this tutorial, we only talk about REST API.

REST stands for "Representational State Transfer". In "REST API Design Rulebook", the author explains further:
  • A Web API is the face of a web service, directly listening and responding to client requests. 
  • A Web API conforming to the REST architectural style is a REST API 
  • Having a REST API makes a web service “RESTful.” 
This is a quick video to cover this concept from Todd Fredrich.
And another simple reading from MuleSoft about RESTful API
While REST can be used over nearly any protocol, as API vs Web Service mentioned: "REST APIs are a standardized architecture for building web APIs using HTTP methods."

HTTP Methods
If you're testing a REST API, you need to understand the basic idea of HTTP Methods. API vs Web Service introduced two: 
  • GET
  • POST
We using Get request to get data and using Post request to create data. We will add one more method you will need:
  • PUT
Put can also be used to create data. The difference between PUT and POST is, POST is usually used to create a resource even you don't know the specific URL, while PUT is usually used to overwrite a resource for an update, or created if it doesn't exist.

For example, you can use a POST request to create a customer without specifying the customer Id, and the POST request will generate a new customer with customer Id. And you can use a PUT request to update a specified customer's address, and it will create an address if the customer doesn't have one.

Here's a good read to explain the difference between those two. 
URIs

Let me add a little extra here, when we using HTTP to visit a website, we will need an URL, such as http://www.google.com

And for a REST API, you will need something similar, a URI.

URL is one type of URI. You can find the difference between two in here from Milecia McG

This is a dummy API I found online can help you understand REST API more visually:
The second API in the list will return you a single user with user id 2, and you can get the API response by directly put the URI into a web browser. 
You probably will hear a term called endpoint as well when we talked about REST API. The endpoint indicates how you access the resources. An endpoint is part of the URI. In the above example, the endpoint would be "/api/users/2"
You can have a read about endpoint in this document from Tom Johnson.
JSON
The last basic idea you need to know is JSON.

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It's easy for humans to read and write.

The REST architecture allows API providers to deliver data in multiple formats such as XML, HTML, and JSON. And JSON is one of the most popular format API using.

Have a bit read about SOAP vs REST vs JSON comparison from Anna Monus to understand REST and JSON better.

Wrap up

Let's do a quick wrap up:
  • Now you should already have a better understanding of these basic concepts: APIs, REST, HTTP, URIs, JSON. 
  • If you read all the recommended reading, you should have a good idea around what a REST API looks like.
  • And if you had a look at the dummy API we found, you should able to send an API request and get a response from https://reqres.in/api/users/2 through a web browser. 
What's next
In our next tutorial, we will show you how to use a tool called Postman to test a simple API. 

Further reading

If you're interested in more knowledge around APIs, here are few blogs that could be used as a reference when you study more by yourself:

How to design a REST API - Antoine Chantalou, Benoit Lafontaine, Mohamed Kissa, Florent Jaby, Jérémy Buisson, Augustin Grimprel, Nicolas Laurent

API, Web Services & Microservices Testing Pathway - Katrina Clokie


Comments