Rest Assured - Java

Fetch the node value from json array 

payload and api call -> https://reqres.in/api/users?page=2

import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;

public class api1stDay {
public static void main(String[] args) {

Response res = RestAssured.given().contentType("application/json").when().get("https://reqres.in/api/users?page=2").then().extract().response();
JsonPath jsn = new JsonPath(res.asString());
int size = jsn.getList("data").size();

for(int i=0;i<size;i++){
System.out.println(jsn.get("data["+i+"].email").toString());
}
}
}

import io.restassured.RestAssured;

import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;

import java.util.HashMap;

public class api1stDay {
public static void main(String[] args) {
HashMap< String, String > data = new HashMap<>();
data.put("name", "morephus");
data.put("job", "leader");
Response r= RestAssured.given().contentType("application/json").body(data).when().post("https://reqres.in/api/users").then().extract().response();
System.out.println(r.asString());
Response r1=RestAssured.given().contentType("application/json").get("https://reqres.in/api/users?page=2").then().extract().response();
System.out.println(r1.asString());
JsonPath j=new JsonPath(r1.asString());
System.out.println(j.getInt("page"));

}
}


upload file using restassured 

-> Response response = given().multiPart("file", file, "text/plain").multiPart("fileName", fileName).multiPart("description", description).when ().post ( "/uploadFile");

API Status Code  





Comments