What is REST-assured?
There are many ways to perform the REST assured API testing like using POSTMAN client, cURL, JMeter, SOAPUI. Apart from that, Java-based API test framework can be used (Apache HTTP Client, Jersey Test Framework and Rest assured).
Testing and validating REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of using these languages into the Java domain.
Example: This example for basicly usage of Rest Assured for your API Automation. We are trying to get some data from API response.
(GET) –> https://reqres.in/api/users/2
"company": "StatusCode Weekly",
"text": "A weekly newsletter focusing on software development, infrastructure, the server, performance, and the stack end of things."
Automation Script: We have learned how is dummy API working and responding manually. Now we are ready to automate this with Rest Assured. Finally we will add 3 test assertions (verifications). If any assertion fails, test will be marked as failed.
- Response Status is 200 (successfull)
- Body data.email value equals to “firstname.lastname@example.org”
- Getting reponse less than 2 seconds.
when(). get("/api/users/2"). then(). statusCode(200). body("data.email", equalTo("email@example.com")). time(lessThan(2000L));
You can read this tutorial “Quick Start with API Automation” to learn how to do it with MomentumSuite.