How to write automation scripts for POST Method using REST ASSURED

person in white shirt using computer
Reading Time: 2 minutes

POST Method:

POST method is used to send data to a server to create/update a resource. The data sent to the server with this method is stored in the request body of the HTTP request.


Rest Assured enables you to test REST APIs using java libraries and integrates well with Maven. It has very efficient matching techniques, so asserting your expected results is pretty straightforward. In addition, it has methods to fetch data from almost every part of the request and response no matter how complex the JSON structures are.

Advantages of Rest ASSURED are:

  • Rest Assured is a group of java libraries that enables us to automate Rest API testing.
  • It helps fetch values of requests and responses from complicated JSON structures
  • The API request can be customized with a variety of header, query, path param, and any session or cookies to be set.
  • It helps set assert statements and conditions.
  • While Rest Assured is very helpful when the response is JSON type. Its methods may not work seamlessly if the content type is HTML or plain text.

Automation scripts for the POST Method using REST ASSURED are:

  1. First, we create a java maven project in IDE. Then add dependencies in the pom.xml file below are the dependencies we added are:

2. Then we create an class and in that class declare a method for a POST request using REST ASSURED this is a POST request we also use the body to create a new request

3. After that we create a class and call a method that we declare in an class and run the test using @Test annotation . In addition, we will see if our test is passing or failing and we are also using assertion for that.

As you can see our test is passed successfully.

Likewise, we can create automation scripts of HTTP methods like GET, POST, PUT, DELETE, and many more using REST ASSURED . Also, we can use assertions to verify that.


Written by 

I am a software Consultant-QA at knoldus Inc in test automation studio. She is familiar with the core concepts of manual testing and automated testing using Selenium and cypress. She is always eager to acquire new tech skills and learn new & advanced concepts to advance herself. She likes to watch web series and listening music.