Complete REST Assured Interview Questions & Answers

REST Assured Interview Questions and Answers

REST Assured Interview Questions & Answers (Advanced)

1. What is REST Assured?

Answer: REST Assured is a Java-based library used to automate RESTful APIs. It simplifies HTTP request creation and response validation using BDD-style syntax (given-when-then). It integrates easily with TestNG, JUnit, Maven, and CI/CD tools.


2. What are the advantages of REST Assured?

  • Easy-to-read BDD syntax
  • Supports JSON & XML
  • Built-in validation for status codes, headers, body
  • Supports authentication (OAuth, Basic, Bearer)
  • Seamless CI/CD integration

3. Explain BDD syntax in REST Assured

  • given() → Request specification (headers, params, auth)
  • when() → HTTP method (GET, POST, PUT, PATCH, DELETE)
  • then() → Response validation

4. How do you validate status code?


given()
.when()
    .get("/users/1")
.then()
    .statusCode(200);

5. How do you validate response body?


given()
.when()
    .get("/users/1")
.then()
    .body("data.id", equalTo(1));

6. How do you validate response headers?


.then()
    .header("Content-Type", "application/json");

7. How do you pass query parameters?


given()
    .queryParam("page", 2)
.when()
    .get("/users")
.then()
    .statusCode(200);

8. POST request example


given()
    .contentType("application/json")
    .body(payload)
.when()
    .post("/users")
.then()
    .statusCode(201);

9. Difference between PUT and PATCH

  • PUT → Updates full resource
  • PATCH → Updates partial resource

10. PUT request example


given()
    .contentType(ContentType.JSON)
    .body(payload)
.when()
    .put("/users/1")
.then()
    .statusCode(200);

11. PATCH request example


given()
    .contentType(ContentType.JSON)
    .body(partialPayload)
.when()
    .patch("/users/1")
.then()
    .statusCode(200);

12. DELETE request example


given()
.when()
    .delete("/users/1")
.then()
    .statusCode(204);

13. Authentication types supported

  • Basic Authentication
  • Bearer Token Authentication
  • OAuth 2.0
  • API Key Authentication

14. Basic Authentication example


given()
    .auth().basic("username", "password")
.when()
    .get("/secure")
.then()
    .statusCode(200);

15. Bearer Token Authentication


given()
    .header("Authorization", "Bearer " + token)
.when()
    .get("/users")
.then()
    .statusCode(200);

16. OAuth 2.0 Authentication


given()
    .auth().oauth2(token)
.when()
    .get("/profile")
.then()
    .statusCode(200);

17. Extract response values


String id = given()
.when()
    .get("/users")
.then()
    .extract().path("data[0].id");

18. API Chaining

Using response data from one API as input for another API.


int userId = given()
.when()
    .post("/users")
.then()
    .extract().path("id");

given()
.when()
    .get("/users/" + userId)
.then()
    .statusCode(200);

19. JSON Schema validation


.then()
    .body(matchesJsonSchemaInClasspath("schema.json"));

20. Logging request & response


given()
    .log().all()
.when()
    .get("/users")
.then()
    .log().all();

Best Practices

  • Use Request & Response Specifications
  • Externalize test data
  • Validate status code first
  • Handle auth dynamically
  • Integrate with Jenkins

"I focus on building scalable, maintainable API automation frameworks that validate business logic, security, and data integrity while integrating seamlessly into CI/CD pipelines."
Masum Raza
Senior Automation Test Engineer

Popular posts from this blog

Explore essential Java programs commonly asked in interviews, offering valuable coding insights and practice.

Here is the content refined for clarity and professionalism suitable for someone preparing for a QA Automation interview:

Comprehensive Selenium WebDriver Syntax for Effective Test Automation