API Testing using Postman
API Testing is essential, no matter which API you are using
Difficulty: Beginner | Easy | Normal | Challenging
Making API calls from any application is essential in most, if not all projects of any scale. How do you know if an issue with the client-server relationship is from the client or the server?
When you need to create an API call you should be using Postman to support your development.
This guide is a step-by-step tutorial on how to use Postman with a fake API endpoint provided by https://reqres.in
- None, although you will need to be able to download and install applications on your chosen platform.
If you do wish to understand HTTPRequests, you might like to look at this article explaining them
API: Application programming interface. A set of accessible tools for building software applications
Endpoint: An endpoint is a remote computing device that communicates back and forth with a network to which it is connected
GET request: requests data from a specified endpoint
HTTP request: A packet of information that one computer sends to another computer to communicate with it
POST request: sends data to a specified endpoint to create or update a resource
Token: this represents the authorization of a specific application to access specific data
url: Uniform Resource Locator. An address of a web page or resource
- Go to https://www.getpostman.com/apps and download and install the application for your platform
The API to call
- Look at https://reqres.in (to make sure it is running, if nothing else) — this is the API we are going to call in this article
Configure and use Postman
The GET request
We are going to make a GET request to /api/users?page=2 , which just happens to be the first request on the reqres page. Just follow the steps!
Create a new collection
A collection in Postman helps us keep the requests we make both tidy and together (much like a folder).
Through the menu we select File>New…
Then Select Collection
I’ve called my collection TestAPI
Make a new request
A new request can be made by selecting New>Request
Make sure that you have selected where to save your new request — obviously you’ll want to place this in the collection you’ve just created!
I’ve called my request users
Fill in the data for a new request
We will fill in https://reqres.in/api/users?page=2 into the box beside “GET”. Since this is a GET request we’re in the right place!
There aren’t any further parameters, so we can…
Make the request
Click the friendly blue button, and you make the request. The right-hand panel should show the response, and this will be something like the following:
With the entire process looking like the following:
Well done! This is your first successful API request!
The POST request
We are going to call /api/register from the same server. This is slightly different to the GET request, as some data (an email and password) need to be sent to the server.
We are calling register, since you need to register before logging in (much like any usual endpoint you need to register before you can login to a service — this shouldn’t be too shocking!)
Create a new collection and a new request
Note: This request will be added to the same collection as above, and I’m going to call this request register for obvious reasons.
Fill in the data for a new request
We will fill in https://reqres.in/api/register (much like before) but this time we need to make this a POST request, and also give an email and password in order to register. The username and password need to be in the defined users list of the website — meaning that I’m going to use email@example.com and pistol. It should be noted that the type of body is x-www-form-urlencoded for this particular address.
The step-by-step is to choose the request to be a POST request, select body for the parameters and add the email and username.
Once again we press the friendly looking POST button (in blue) and expect to get the following response:
This means that we have received a rather attractive token!
This guide has taken you from a GET request to a POST request, and believe
Extend your knowledge
- You might like to read this guide around REST and CRUD
The Twitter contact:
Any questions? You can get in touch with me HERE