Introduction to API Testing Using Rest Assured-Part 2


Introduction to API Testing Using Rest Assured-Part 2


In this blog, we are going to continue with a few more basic terminology that we will be using very frequently while doing API Testing.

Before Moving Further, I would highly recommend you to read the part-1 blog as this blog is a continuation of that.

What Are Payloads?

A Payload is the body of the HTTP request or response.

When browsing the Web, the Browser usually receives an HTML payload. This is the web page that you see rendered in the Browser.

Typically when working with an HTTP API we will send and receive JSON or XML payloads.



What Is JSON?

JSON stands for JavaScript Object Notation and is a text representation that is also a valid JavaScript code.

Below is the sample JSON File.


JSON can be thought of as a hierarchical set of key/value pairs where the value can be:

• Object - delimited by { and }.
• Array - delimited by [ and ].
• String - delimited by " and ".
• Integer

An array is a list of objects or key/value pairs.
The keys are String values e.g. “projects”, “project”, “id”, etc.


What Is XML?

XML stands for Extensible Markup Language.HTML is a variant of XML.

For XML to be valid, it must be well formed, meaning that every opening tag must have a corresponding closing tag, and strings must have an opening and closing quote.

Below is the Sample XML File

Some elements do not have a closing tag, these are self-closing. The opening tag, instead of ending with > actually ends with /> you can see this in the <description nil=" true"/> element.
  
HTTP messages have the Verb and URL, followed by a set of headers, and then the optional payload.


POST http://www.google.co.in/apps/mocktracks/reflect.php HTTP/1.1
Host: www.google.co.in
Content-Type: application/json
Accept: application/json
{"action":"post"}


The headers are a set of metadata for the message.

Headers are a name, followed by:, followed by the value of the header.'

The above HTTP message example has three headers:
• Host
• Content-Type
• Accept

The Host header defines the destination server domain name.

The Content-Type header tells the server that the content of this message is JSON.
The Accept header tells the server that the client (application sending the message) will only accept response payloads represented in JSON.

There are many headers available for configuring the Authentication details, length of the message, custom metadata, cookies etc.



What Is Authentication?

When we send a message to a server we might need to be authenticated i.e. authorized to send a message and receive a response.

For many Web Applications, you authenticate yourself in the application by logging in with a username and password. The same is true for Web Services or HTTP APIs.

If you are not authenticated and try to send a message to a server then you are likely to receive a response from the server with a 4xx status code e.g.

• 401 Unauthorized
• 403 Forbidden
There are many ways to authenticate HTTP requests for HTTP APIs.

Some common approaches you might encounter are:
• Custom Headers
• Basic Authentication Headers
• Session Cookies


What Is REST?

A REST (Representational State Transfer) API defines a set of operations where developers can perform requests and receive responses via HTTP protocol. 

ร˜  REST API’s use HTTP, they can be used by practically any programming language.
ร˜  It acts as a medium to propagate communication between the client and server applications on the World Wide Web.
ร˜  Stateless – No client data is stored on the server between requests and session state is stored on the client.
ร˜  HTTP is the transport protocol for REST

In the Next Blog, we will look into some Rest API Program.





SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post