GET & POST API Testing using POSTMAN

Novita Tamba
4 min readFeb 20, 2021

Application programming interfaces, or APIs, enabling applications to exchange data and functionality easily and securely.

API TESTING is a software testing type that validates Application Programming Interfaces (APIs). The purpose of API Testing is to check the functionality, reliability, performance, and security of the programming interfaces. (Ref: Guru99). API Testing requires an application that can be interacted via an API and in this case, I use Postman.

Postman is a popular API client to send a request and get a response from the web server. Apart from being used for API Development, this tool also used for comprehensive API testing tool.

Follow the steps in the link to Install Postman.

Hands-On

I try to use open API (as link attached) to demo an API Call simulation and Writing Test Script for 2 GET Method (/users, /posts) and 1 POST Method (POST /public-api/users).

  1. GET Request — For Retrieving/Fetching data
  2. POST Request — For Creating Or Updating data

Set Environments

First thing first, after installation successfully, configure an environment that saves global or general variables. Store base URL, for example, could make API Request maintain easily since I’m not writing the Base URL many times in every request. I also maintain test data through name_input variable ($randomFirstName) that randomly generated a name when POST Request is running.

To configure the value, simply click on the Environments menu, and enter variable/s in the specified sections and click Save.

Set Collections and make API Requests

Postman’s collection is folders that make it easy to keep API requests and elements organized. To create a Collection, right-click on Collection under the My Workspace tab, and click Create new collection button (+). Then, make API Request for 3 Method as mention above.

  1. GET Method :
  • Under Test Collection, Create a new request using + Icon in the Tab
  • Enter {{url}}/users in the URL Field (next to GET Method)
  • Click on Send and you will see the JSON data response from the server in the lower pane.
GET Method

2. POST Method :

  • Under Test Collection, Create a new request using + Icon in the Tab
  • Choose POST from Dropdown Value (besides URL Field)
  • Enter {{url}}/users in the URL Field
  • Enter Headers as follow → “Accept:application/json”; “Content-Type:application/json”; “Authorization: Bearer ACCESS-TOKEN
  • Enter Request Body / Contains data to be sent with the Request. Enter name, gender, email and status as sample data below.
  • Click on Send and you will see the JSON data response from the server in the lower pane
POST Method

Note: Request methods POST needs access token, which needs to be passed in the “Authorization” header as Bearer token.

Write Test Script for API

Following the API Requests, I start to write test scripts for all Methods in the TESTS Menu (Right after the Pre-requisite Script).

In this case, I write 2 test script for each Request (A Total of 6 Scripts). These are postman basic function that you can find on Snippet (beside of Test Area).

e.g for GET Method :

  • pm.test — postman test/check if the response code received is 200 (OK).
  • pm.expect — postman expect/check whether a JSON value id is equal to 10
GET Method Test Script

The same test script for POST Method, except for JSON data which I prefer to validate the Gender instead of ID.

POST Method Test Script

Note: Status Code is an indication of whether a specific HTTP request has been completed. Responses are grouped into five classes:

https://www.restapitutorial.com/httpstatuscodes.html

Run Test using Collections Runner

The Collection Runner enables a set of test script run in specified sequences. Click on the Run button to start and set information such as Iteration, Delay, Data and perform the final step by click on Run Test Collections.

Result ✌️

Subsequently, Postman will display all request executions and test results status (PASS/FAIL) in realtime. In the picture below, you can see an overview for each request, how many tests do each request have, descriptions for each test, time executions and status code returned. Export into JSON Report is also available by click on Export Result.

Thank you for reading 💛

--

--