Introduction:
REST-assured enables you to test REST APIs using java libraries. It is very efficient and easy to use. Integration with maven is also easy. REST-assured has methods to fetch data from every request and response part.
It can be used to test XML & JSON-based web services, however, the structure is complex.
Pre-requisite:
- JDK should be installed in the system.
- IDE for running and executing java code (either eclipse or other).
Installations:
Firstly, you must create a new maven project in your eclipse IDE. Then we need to add a dependency for rest assured and testNG to execute code for API testing.
The below dependency is for REST-assured added to your pom.xml file in your maven project.

Apart from that, you need to add TestNG framework to your maven project. For that, you need to add a dependency for TestNG.

Then, you need to go to src/test/java in your maven project and you can either create a new java class or write code in the default class.
Syntax:
The syntax of REST-assured is easy and similar to the BDD structure. It uses given/when/then, therefore it is easy to understand and readable.

Create [POST]:
To create data using REST-assured we use post() method. Firstly, we should have data in the form of JSON Object and authorization tokens as needed. Using TestNG as testing framework we can post any request as defined in the code below:
By getting status code as 201. That means your data is created successfully.

Read [GET]:
To read the data using get() request in REST-assured with TestNG framework use the code below.

Update [PUT]:
To update data using REST-assured we use put() method. Firstly, we should have data in JSON Object and authorization tokens as needed. Using TestNG as a testing framework we can update any data as defined in the code below:
By getting the status code as 200. That means your data is updated successfully.

Delete [DELETE]:
To DELETE the data using REST-assured and get response code as 204. The code for DELETE request is below.

Pros:
- It is easy to use since it uses given/when/then test notations which are readable easily.
- Easy to integrate with frameworks like TestNG and JUnit.
- Code reusability is excellent as it is a Java client.
- CI/CD integration is easy as we can easily integrate with tools like Maven and Jenkins.
- REST-assured can be used with customized and open-source reporting tools.
- It provides DSL so the test is Behaviour driven.
- It provides an easy interface, which is why it is a better tool rather than other complex tools.
Cons:
- Does not support SOAP APIs explicitly.
- There is no inbuilt reporting in REST-assured.
- Since it uses Java as a programming language thus requires good knowledge of Java.