Postman API Testing

Postman API Testing

Postman is one of the most widely used API testing tool now. Find below the concept for Postman API Testing.

Frequently asked Postman API Testing questions.

Explain 3-tier architecture

All web application comes under 3 tier architecture. It consists of three layers.

  1. Client / Presentation-  It is the presentation layer from which the user sends the request. Like Browsers.
  2. Business Logic- As soon as the user sends the request from the client layer corresponding business logic gets executed. Business logic will pass the request to the database layer and vice versa.
  3. Database- As per the request from the business logic database provide the set of data.

Business Logic acts as a mediator between the client and database, it contains business logic written in programming language collectively known as API. Business Logic takes input from the client and sends back the output to the client after interacting with the database.

What is API?

API means Application Programming Interface. It enables communication and data exchange between two separate software systems (client and server).

Explain is API Testing?

API testing mainly concentrates on the business logic layer of the software architecture. In API testing we use software to send calls to the API, get output and note down the system response. API testing needs a system to interact with the API. In order to test an API, you will need to-

  • Use a Testing Tool to drive the API
  • Write your own code to test the API

What is Web Services?

All web services are API but all APIs are not web services. When we put the APIs over a network they are called web services. Whenever a developer develops the API first we test them in the local environment without internet after testing we move those APIs to the production environment and then the same APIs are available on the network.

Difference between API and Web Service

1Web Service is an API wrapped in HTTP
2All web services are API but all APIs are not web services
3Web Service might not perform all the operation that an API would perform
4Web Service need a network while an API doesn’t need a network for the operation

What is a URI?

Uniform Resource Identifier, URI consists of base URL, path parameter, and query parameter

URI= Base URL + Path Parameter + Query Parameter

Example: 

URI-   https://reqres.in/api/users?page=2

Base URL-  https://reqres.in

Path Parameter- /api/users

Query Parameter- ?page=2

Explain HTTP requests.

GETRetrieve data from the server
POSTCreate a new resource/record in the server
PUTUpdate the existing record
DELETEDelete the existing record

For every POST and PUT request, we send the payload (data) along with the request.

What is a response?

For every HTTP request we get a response in JSON / XML / HTML / Text  etc and perform our validations on that response.

Describe a GET Request and its components.

REQUESTGET
URIhttps://reqres.in/api/users?page=2
RESPONSEReturns list of users on a page
STATUS CODE200
Validationtests[“Validating Status Code”] = response code.code == 200;
tests[“Validating response body”] = response body.has(“data”);
var response = JSON.parse(response body);
tests[“page no”] = response.page == 2;

GET request is used to retrieve data from the server

The body is not required while executing a GET request

So when we will execute the above GET request in the postman we will get a response in the JSON format. Once you get the response you have to focus on a few things

Response Body: We will perform our validations in the response body

Status Code: We the status code is 200 or 201, the request is successful.

Time of execution

Data size

Headers: In every response, we will get data in headers, these are server-related data, we should verify proper headers are created or not.

Cookies: Sometimes we will have multiple cookies or single cookies created, so we need to check this.

Test Result: Once we will add the validation points, the test result will be displayed.

How we can add validation points in postman?

Once we will send a request we will get a response body and in the Test tab we can add the validation points like:

1- Validating the Status Code:

tests[“Validating Status Code”] = responseCode.code == 200;

2- Next validating data in the response body:

tests[“Validating response body”] = responseBody.has(“data”);

3- Validating data in speficic field in the response body:

var response = JSON.parse(responseBody);

tests[“page no”] = response.page == 2;

We have added 3 validation, even one validation failed the entire test will fail.

What is the difference between the path parameter and query parameter?

query parameter will filter the data.

Example: https://reqres.in/api/users?page=2

path parameter will simply get the data based on the path we specify.

Example: https://reqres.in/api/users/2

Describe a POST Request and its components.

HTTP REQUEST TYPEPOST
URIhttps://reqres.in/api/users
BODY{
“name”: “morpheus”, “job”: “leader”
}
SUCCESS RESPONSE

{
“name”: “morpheus”, “job”: “leader”,
“id”: “256”, “createdAt”: “2018-07-
07T05:43:53.310Z”

}

FAILURE RESPONSENA
STATUS CODE201
COMMENTSCreate
Validation

var response = JSON.parse(responseBody);

tests[“name”] = response.name == “morpheus”;

tests[“job”] = response.job == “leader”;
tests[“Validating Status Code”] = responseCode.code == 201;

While sending POST request, we need to send the payload (body) along the request in the JSON format. It will create a new record in the database. Once you will execute the POST request you will get the response on which you can perform the validation part.

What is the other use of POST requests?

A POST request is also used for authentication and data validation. Consider the login scenario, we pass the user name and password as a payload with the POST request it then validates the user name and password from the database and generates a token, and completes the authentication process.

HTTP REQUEST TYPEPOST
URIhttps://reqres.in/api/login
BODY{
“email”: “peter@klaven”, “password”: “cityslicka”
}
SUCCESS RESPONSE

{ “token”: “QpwL5tke4Pnpja7X” }

FAILURE RESPONSENA
STATUS CODE200
COMMENTSLogin Success
Validation

tests[“Validating Status Code”] = responseCode.code == 200 ;

tests[“Validating Token presence”] = responseBody.has(“token”);

Describe a PUT Request and it’s components.

REQUESTPUT
URI

http://dummy.restapiexample.com

/api/v1/update/21

BODY

{“name”:”test1″,

“salary”:”1 123″,”age”:”23″}

STATUS CODE200
ValidationPerform a GET request and
validate the updated data
SUCCESS
RESPONSE

{“name”:”test1″,

“salary”:”1123″,”a ge”:”23″}

If the record is already available, using PUT request we can update the existing record. Request payload (body) is an important part of the PUT request. So while adding the payload keep a primary field with it along with the fields that you want to update.

Define a DELETE Request and its components.

HTTP REQUEST TYPEDELETE
URI

http://dummy.restapiexample.com

/API/v1/delete/700

BODYNA
SUCCESS RESPONSE

{“success”:

{“text”:”successfully! deleted Records”}}

FAILURE RESPONSENA
STATUS CODE200
COMMENTS

Delete an employee record

Path Parameter:/delete/{id}

ValidationPerform a GET request and verify

Delete request will directly delete record the one which we will specify in the URL

CHECK NEXT PART

About Postman

1 thought on “Postman API Testing”

Comments are closed.