java rest api testing framework code example

Example: API/Webservices with RestAssured Library?

import static io.restassured.RestAssured.* ;
URI uri = new URI(" ... / methods(get, post))
GET;
Response response =
given().accept(ContentType.JSON).
when().get(URI);
response.
then().assertThat().statusCode(200).
and().assertThat().ContentType(ContentType.JSON);

POST;
Response response =
given().ContentType(ContentType.JSON).with().
accept(ContentType.JSON).and().body(JSONbody).
when().post(URI);
response.
then().assertThat().statusCode(200);

Tags:

Java Example