RestAssured Framework

Rest assured is the framework written in Java to test rest and soap services.

How to use Rest API

Just follow below steps to test rest apis.
  1. Create a request
  2. Send get or post request to server
  3. Read the response and do assertions
You can create a request as shown in below example
 RestAssured.baseURI = url;

 RestAssured.requestSpecification = new RequestSpecBuilder().
                addHeader("Content-Type", "application/json").
                addHeader("Origin","https://xyz.com.au").build();
Then Send the get request
 Response response = given().when().get();
        response.print();
You can send the post request as shown in below example
Response response = given()
  .body("{\"quoteRequests\":[{\"@type\":\"imt/1-0-0/quoteRequest\",\"@type\": 
  \"xyz/1-0-0/quoteRequest\",\"from\":{\"amount\":100,\"currency\":\"AUD\"},
  \"to\":\"USD\",
  \"created\":\"2018-11-23T06:17:31.818589Z\"}], \"verticals\":[\"xyz\"]}")
  .post();

Then you can do assertions as shown below.
assertThat(response.getStatusCode()).isEqualTo(200);
List results = response.jsonPath().getList("code");
assertThat(response.jsonPath().getList("label")).contains("Australian Dollar");
assertThat(response.jsonPath().getList("symbols").get(0)).asList().contains("24");

        response.print();
        assertThat(response.getStatusCode()).isEqualTo(200);


        
        
 

     
Youtube | Facebook | Twitter | Website Home | Online Grocery Shopping Brisbane