Information Technology - Blog V-Soft Consulting

API Testing Process Using REST Assured and PostMan Tool

Written by Charan Sai Dasagrandhi | Sep 20, 2019 8:12:41 AM

APIs stand as enablers to conduct risk-free legacy modernization and drive businesses toward digital transformation. APIs should be precisely optimized to fulfill a specific business request in a specific context. To ensure a robust API, API testing is the key to success. API testing can be performed either manually using POSTMan tools or by automation using available dependency code for Rest Assured. Here we are going to discuss API Testing with REST Assured and API testing with PostMan Tool.

What is REST Assured?

The objective of REST Assured is to simplify the process to test and validate RestAPI. The Rest Assured is a Java-based library used to validate HTTP responses received from the server. For example, we can verify the Status Code, Status Message, Headers and the Body of the response. This flexibility of the REST Assured library can be used for API testing.

 

Comparing Operations in Rest-Assured and Manual API testing in POSTMAN

Generally four basic operations are performed using the REST interface: Create, Read, Update and Delete. These four collectively termed as CRUD operations. All these operations are performed either manually using tools like POSTMAN or automated using Rest Assured or Rest API libraries.

Let's look at the CRUD in detail:

Create Operation Performed Using the POST or post() Method

  • Using the post(), we can perform changes to the server.
  • Here, resources are created on the server and hence, the changes are done to the server.
  • Example: Uploading the picture on Facebook where we perform the changes to the Server on top of the existing resources.
  • Status Code of the Response received is 201.
  • Reason Phrase is “Created”.
  • Code Snippet:



Example 1: Post Request (from Postman)

Example 2: Post Response (from Postman)

Read Operation Performed Using the GET or get() Method.

  1. Using the get(), data is retrieved from the server.
  2. Here, no changes are made to the server or to already existing resources.
    Example: Simple search on Google where we don't alter anything.
  3. Status Code of the Response received is 200.
  4. Reason Phrase is “OK”.
  5. Code Snippet:

:

Example 1: Get Request (from Postman)

Example 2: Get Response (from Postman)

Update Operation Performed Using the PUT or put() Method

  1. Using the put(),we can perform changes to the server on updating.
  2. Here, resources are updated on the server and hence, the changes are done to the server.
    Example: Changing or updating a picture on Facebook where we perform the changes to the server on top of the existing resources.
  3. Status Code of the Response received is 200.
  4. Reason Phrase is “OK”
  5. Body of the request is required and the Path/URL is given for the exact resource to be updated. For example, http://localhost:3000/posts/1 is to be provided to remove the resource with id=1
  6. Code Snippet:

Example 1: PUT Request (From Postman)

Example 2: PUT Response (From Postman)

                                                     

Delete Operation Performed Using the DELETE or delete() Method

  1. Using the delete(),we can delete the existing resources on the server.
  2. Here, resources are deleted on the server.
    Example: Deleting the picture on Facebook where we delete the resource
  3. Status Code of the Response received is 204.
  4. Body of the request is not required and the Path/URL is given for the exact resource to be removed. For example, http://localhost:3000/posts/1 is to be provided to remove the resource with id=1
  5. Code Snippet:


Delete Request (From Postman)

Example 2: Delete Response (From Postman)

Conclusion

The above information related to API testing using the Rest-Assured and Postman tool clearly differentiates both Manual Testing and Test Automation roles. Moreover, it depicts how REST Assured API testing simplifies the process to test and validate RestAPI without any complexities.

About Author

Sandya Chitti N works as a Senior Test Automation Engineer with V-Soft Consulting and has more than 8 years of IT experience in Software Testing and around 6 years of experience as an Automation QA Engineer using Selenium WebDriver. She has sound testing knowledge in Rest API testing, Web & Mobile App (Android & iOS) testing, GUI, Functional, Integration, System, Ad-hoc, Usability, Data Base, Smoke, Regression and Retesting. In her quality testing career, she has  learned alot about Selenium IDE, WebDriver and OATS automation Testing Tools. She is also well versed in programming C, SQL, Core Java, JavaScript and Python.