What is Rest Assured? How to setup Rest Assured?

What is Rest Assured?

REST-assured is an Open Source Java library which is used to test and validate REST APIs. Dynamic languages like Groovy , Ruby are helpful in API testing which was harder in Java. We have a famous Java library named Apache Http Client which is also used to do API Testing but it requires a lot of coding. Rest Assured makes API testing simple in Java.
Representational state transfer is a software architectural style that defines a set of constraints to be used for creating Web services. Web service is a service offered by an electronic device to another electronic device, communicating with each other via the World Wide Web, or a server running on a computer device.

Official Rest Assured Site
Official Documentation of Rest Assured

Advantages of Rest Assured

It is an Open source i.e. free.
It requires less coding compare to Apache Http Client.
Initial setup is easy and straightforward before you hit any endpoint.
Easy parsing and validation of response in JSON and XML.
It follows BDD keywords like given(), when(), then() which makes code readable and supports clean coding. This feature is available from version 2.0.
Very rich in readymade assertion
Quick assertion for status code and response time.
Powerful logging mechanism.
Can be easily integrated with other Java libraries like TestNG, Junit for Test Framework and Extent Report , Allure Report for reporting purpose.
Very good support for different authentication mechanism for APIs.
Can be integrated with Selenium-Java to achieve End to End automation.
Supports JsonPath and XmlPath which helps in parsing JSON and XML response. Rest Assured by default integrates both.
Can be used to verify Json Schema using JSON Schema Validation library.
Includes XML schema validation
Can be integrated with Maven and CICD.

How to setup Rest Assured?

1. Create new maven project
Lets create a maven project for our rest api automation testing.

new project rest assured tutorial onlyfullstack

2. Add Rest Assured and TestNG dependancy
Add below selenium-java maven dependancy to your pom.xml as below –

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>rest-assured-tutorial</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>4.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>3.3.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
3. Setup TestNG in Eclipse
You will need to download the TestNG plugin in eclipse. Please follow below link to install the TestNG plugin in Eclipse.
TestNG Tutorial Part 1 – What is TestNG? How to configure TestNG in Eclipse?

Lets go to our next tutorial where we will discuss below points :

Part 2 – Sample Rest API To Test With Rest Assured

– 1. Clone the below repository
– 2. Run the application
– 3. Install the Postman
https://www.onlyfullstack.com/sample-rest-api-to-test-with-rest-assured/

Source Code
You can find the complete source code on below GitHub repository – 
https://github.com/onlyfullstack/rest-assured-tutorial

Rest Assured Tutorial
https://www.onlyfullstack.com/rest-assured-tutorial-for-beginners/