Q3 of 40 · REST Assured

What is REST Assured and what makes it different from a plain HTTP client?

REST AssuredJuniorrest-assuredfundamentalsapi-testingjava

Short answer

Short answer: REST Assured is a Java DSL that wraps HTTP in a fluent given/when/then chain and bundles JsonPath querying, schema validation, and auth helpers. A plain HTTP client handles transport only — REST Assured adds the test layer: status-code matchers, body assertions, and request/response logging.

Detail

REST Assured sits on top of Apache HttpClient and adds a test-focused API. A raw client call returns an HttpResponse; you parse the body, write assertEquals, and hand-roll all assertions. REST Assured does all of that in one readable chain.

What it bundles:

  • given().when().then() maps directly to Arrange/Act/Assert
  • JsonPath and XmlPath for body querying without manual parsing
  • Built-in Hamcrest matchers (equalTo, hasItem, not, everyItem)
  • Auth helpers: .auth().basic(), .auth().oauth2(), .auth().preemptive()
  • .log().ifValidationFails() for zero-noise request/response debugging
  • .extract().as(MyClass.class) for typed response extraction

REST Assured tests are JUnit or TestNG methods — they slot into an existing Maven/Gradle suite with no new infrastructure required.

// EXAMPLE

BasicRestAssuredTest.java

// Plain HttpClient — verbose, lots of boilerplate
HttpGet req = new HttpGet("https://api.example.com/users/1");
HttpResponse raw = client.execute(req);
assertEquals(200, raw.getStatusLine().getStatusCode());
String body = EntityUtils.toString(raw.getEntity());
assertEquals("Alice", JsonParser.parseString(body).getAsJsonObject().get("name").getAsString());

// REST Assured — same assertion, one chain
given()
    .baseUri("https://api.example.com")
.when()
    .get("/users/1")
.then()
    .statusCode(200)
    .body("name", equalTo("Alice"));

// WHAT INTERVIEWERS LOOK FOR

Knowing REST Assured is a fluent assertion library (not just an HTTP client) and citing specific bundled features — JsonPath, auth helpers, logging. Candidates who have used it name specific capabilities; those who haven't describe it vaguely as 'easier HTTP'.

// COMMON PITFALL

Treating REST Assured as a test runner. It is a library — JUnit or TestNG still runs the tests; Maven/Gradle manages the dependency.