given() builds the request (base URI, headers, auth, params, body), when() sends it with an HTTP method, and then() validates the response with status, header and Hamcrest body matchers using GPath. Use extract() to pull values out for later steps.
Full answer with examplesInterview questions / API
REST Assured Interview Questions
REST Assured is the standard Java DSL for API automation. Expect questions on given/when/then, specifications, serialization and schema validation.
4 questions · 1 beginner· 2 intermediate· 1 advanced
beginner questions
intermediate questions
Build reusable specs with RequestSpecBuilder (base URI, content type, auth, filters) and ResponseSpecBuilder (common status, content type, response-time checks), then apply them with given().spec() and then().spec(). Put them in a base class or client layer so tests only express intent.
Full answer with examplesHow do you handle serialization and deserialization with POJOs in REST Assured?
intermediate 2–5 yrs
Pass a POJO or Java record to body() and REST Assured serializes it with Jackson (or Gson) found on the classpath; use extract().as(Type.class) or a TypeRef for generics to deserialize. Control mapping with Jackson annotations and decide deliberately whether unknown fields should fail tests.
Full answer with examplesadvanced questions
Use the json-schema-validator module's matchesJsonSchemaInClasspath to assert the response contract, kept in sync with the OpenAPI spec. Use filters (implementing Filter) for cross-cutting concerns: auth token injection and refresh, request/response logging on failure, correlation ids, and attaching traffic to reports.
Full answer with examples