How can i get a max value for userId from this rest endpoint? I have to use RestAssured with Gpath syntax

471 Views Asked by At

I have to get a max value for userId using RestAssured and Gpath syntax. I dont know what i should type in body after then.

I have tried so many ways but it does not work.

@BeforeClass
public void setUp() {
    endpoint = "https://jsonplaceholder.typicode.com/posts/";
}


public static Response getJsonPath(String endpoint) {
    return
            when().
                    get(endpoint).
                    then().
                    statusCode(200).
                    contentType(ContentType.JSON).extract().response();
}


@Test
public void maxUserId() {

    Response response = getJsonPath(endpoint)
            .then()
            .assertThat()
            .body();
}
1

There are 1 best solutions below

0
Arun Nair On

You can use like this. i tried and i got 10 as max value.

public static void maxUserId() {

    int maxValue = getJsonPath(endpoint).jsonPath().get("userId.max()");
    System.out.println(maxValue);
}