Here’s a single combined notes pack you can keep as your API Tes ng / RestAssured notebook.
You can copy this into a doc / No on / OneNote / PDF and print.
1. RestAssured BDD Pa ern
Basic structure:
given() // Request setup (input)
.when() // Ac on (HTTP call)
.then() // Valida on (asser ons)
given() – prepare request: base URI, headers, params, body, auth
when() – send request: GET, POST, PUT, PATCH, DELETE
then() – verify response: status code, JSON body, headers, me, etc.
2. given() – Methods, Purpose, Examples, When Ignored
2.1 Summary Table – given()
Method Real-Time Example Purpose When It Can Be Ignored
Set common base URL for If you always pass full URL
baseUri() .baseUri("h ps://[Link]")
API in .get("h ps://...") etc.
Set common endpoint If you pass /users directly
basePath() .basePath("/users")
path in .get("/users")
Define request body For GET/DELETE without
contentType() .contentType([Link])
format (JSON/XML/TEXT) body
Define expected response Op onal if API always
accept() .accept([Link])
type returns JSON
.header("Authoriza on", "Bearer If API doesn’t require that
header() Add a single header
token") header
Not needed if no extra
headers() .headers("key","v1","k2","v2") Add mul ple headers
headers
cookie() .cookie("sessionId", "ABC123") Add a single cookie If API doesn’t use cookies
cookies() .cookies(cookieMap) Add mul ple cookies Same as above
If API doesn’t require
queryParam() .queryParam("page", 1) ?page=1 style parameters
query params
queryParams() .queryParams(paramsMap) Mul ple query params Same as above
If URL has no {}
pathParam() .pathParam("id", 10) /users/{id} → /users/10
placeholders
pathParams() .pathParams(map) Mul ple path params If not required
Send JSON/XML/POJO as For GET/DELETE requests
body() .body(jsonOrPojo)
request body (generally no body)
auth().basic() .auth().basic("user","pass") Basic auth If using token / no auth
If manually se ng header
auth().oauth2() .auth().oauth2("token123") Bearer token auth
instead
For proper HTTPS
relaxedHTTPSValida on() .relaxedHTTPSValida on() Ignore SSL issues
environments
Route via proxy (e.g.
proxy() .proxy("localhost", 8080) If not debugging traffic
Fiddler/Burp)
Custom RestAssured
config() .config([Link]fig()) Advanced usage only
config
log().all() .log().all() Log full request data Op onal (debug only)
log().body() .log().body() Log body only Op onal
log().headers() .log().headers() Log headers only Op onal
2.2 Typical given() Example
given()
.baseUri("h ps://[Link]")
.basePath("/users")
.contentType([Link])
.accept([Link])
.header("Authoriza on", "Bearer token123")
.queryParam("page", 1)
.body("{\"name\":\"Deepika\"}")
.log().all();
3. when() – Methods, Purpose, Examples
3.1 Summary Table – when()
Method Example Purpose When It Can Be Ignored
.get() .when().get() Send GET request Cannot be ignored – you must use an HTTP method
.get("/users") .when().get("/users") GET with path If basePath already set and you call just .get()
.post() .when().post() Send POST request Use when crea ng resources
.post("/orders") .when().post("/orders") POST with path Same as above
.put() .when().put() Full update of resource Use for PUT APIs
.patch() .when().patch() Par al update Use for PATCH APIs
.delete() .when().delete() Delete resource Use for DELETE APIs
.op ons() .when().op ons() See allowed methods Can be ignored unless CORS/OPTIONS tes ng
.head() .when().head() Get headers only Used rarely
Rule: Exactly one HTTP method in when() is required. No method → no request.
3.2 Example
given()
.baseUri("h ps://[Link]")
.contentType([Link])
.body("{\"name\":\"Deepika\"}")
.when()
.post("/users");
4. then() – Methods, Purpose, Examples, When Ignored
4.1 Summary Table – then()
Method Example Purpose When It Can Be Ignored
Validate HTTP Should never be ignored in real
.statusCode(int) .then().statusCode(200)
status tests
Validate JSON
.body(path, matcher) .body("name", equalTo("Deepika")) Op onal but recommended
field
Validate array
.body(...hasItem()) .body("roles", hasItem("admin")) Op onal
contents
.header("Content-Type", Validate header
.header(name,matcher) Op onal unless contract requires
containsString("json")) values
.log().all() .then().log().all() Log full response Op onal (debug only)
.log().body() .log().body() Log body only Op onal
Log only status
.log().status() .log().status() Op onal
line
Extract field for Op onal, needed when you reuse
.extract().path() .extract().path("id")
reuse in next requests
Get Response
.extract().response() .extract().response() Op onal
object
Validate
. me() . me(lessThan(2000L)) Op onal unless performance check
response me
4.2 Typical then() Example
.then()
.log().all()
.statusCode(201)
.body("name", equalTo("Deepika"))
.body("status", equalTo("ACTIVE"))
.header("Content-Type", containsString("applica on/json"));
5. JsonPath – All Pa erns for All JSON Types
Assume:
Response res = ...;
JsonPath jp = [Link]();
5.1 Root Object
{
"id": 10,
"name": "Deepika",
"ac ve": true,
"score": 99.5
}
Requirement JsonPath Java
id id int id = [Link]("id");
name name String name = [Link]("name");
ac ve ac ve boolean a = [Link]("ac ve");
score score double s = [Link]("score");
5.2 Nested Objects
{
"user": {
"id": 10,
"profile": {
"name": "Deepika",
"city": "Vizag"
}
}
}
Requirement JsonPath Java
user id [Link] [Link]("[Link]");
name [Link]fi[Link] [Link]("[Link]fi[Link]");
city [Link]fi[Link] [Link]("[Link]fi[Link]");
5.3 Root Array
[
{ "id": 1, "name": "Deepika" },
{ "id": 2, "name": "Vinod" }
]
Requirement JsonPath Java
array size size() int size = [Link]("size()");
first name [0].name [Link]("[0].name");
second id [1].id [Link]("[1].id");
all names name List<String> names = [Link]("name");
5.4 Object with Array of Primi ves
{
"tags": ["api", "java", "restassured"]
}
Requirement JsonPath Java
full array tags List<String> tags = [Link]("tags");
first tag tags[0] [Link]("tags[0]");
size [Link]() [Link]("[Link]()");
5.5 Object with Array of Objects
{
"courses": [
{ " tle": "Selenium", "price": 50 },
{ " tle": "API", "price": 40 }
]
}
Requirement JsonPath Java
array size [Link]() [Link]("[Link]()");
first tle courses[0]. tle [Link]("courses[0]. tle");
second price courses[1].price [Link]("courses[1].price");
all tles courses. tle List<String> tles = [Link]("courses. tle");
5.6 Nested Array + Object
{
"dashboard": { "purchaseAmount": 910 },
"courses": [
{
" tle": "Selenium",
"details": { "site": "rahulshe [Link]" }
}
]
}
Requirement JsonPath
purchaseAmount [Link]
tle courses[0]. tle
site courses[0].[Link]
5.7 Using find { } (Groovy) – Array Search
{
"courses": [
{ " tle": "Selenium", "price": 50 },
{ " tle": "API", "price": 40 }
]
}
Requirement JsonPath Java
courses.find { it. tle == 'API'
price of API course [Link]("courses.find { it. tle == 'API' }.price");
}.price
en re Selenium courses.find { it. tle == Map<String, ?> map = [Link]("courses.find { it. tle ==
object 'Selenium' } 'Selenium' }");
5.8 Special Keys / Tricky Keys
{
"user name": "Deepika",
"@meta": {
"created-at": "2025-01-01"
}
}
Requirement JsonPath Java
key with space ['user name'] [Link]("['user name']");
key star ng with @ ['@meta'].['created-at'] [Link]("['@meta'].['created-at']");
5.9 Deep Nested Example
{
"company": {
"departments": [
{
"name": "QA",
"employees": [
{ "name": "Deepika", "id": 1 },
{ "name": "Vinod", "id": 2 }
]
}
]
}
}
Requirement JsonPath
department name [Link][0].name
2nd employee name [Link][0].employees[1].name
id of employee named Deepika [Link][0].employees.find { [Link] == 'Deepika' }.id
6. Complex E-Commerce API Contract (Full Sample)
Base URL: h ps://[Link]
6.1 POST /orders – Create Order
Request:
URL: POST /orders
Headers:
o Content-Type: applica on/json
o Authoriza on: Bearer <token>
Request Body:
{
"customerId": 12345,
"shippingAddress": {
"line1": "Flat 101",
"line2": "Sai Residency",
"city": "Hyderabad",
"postalCode": "500081",
"country": "IN"
},
"items": [
{ "productId": "P1001", "name": "Selenium Book", "quan ty": 2, "price": 500.0 },
{ "productId": "P2001", "name": "API Tes ng Course", "quan ty": 1, "price": 1500.0 }
],
"payment": {
"method": "CARD",
"transac onId": "TXN-98765"
},
"notes": null
}
Response (201):
{
"orderId": "ORD-2025-0001",
"status": "PLACED",
"totalAmount": 2500.0,
"currency": "INR",
"customer": {
"id": 12345,
"name": "Deepika",
"vip": true
},
"items": [
{ "productId": "P1001", "quan ty": 2, "lineTotal": 1000.0 },
{ "productId": "P2001", "quan ty": 1, "lineTotal": 1500.0 }
],
"meta": {
"created-at": "2025-12-07T10:15:00Z",
"source": "web",
"@trackingId": "abc-123-xyz"
}
}
Test Code:
@Test
public void createOrder_shouldMatchContract() {
String baseUrl = "h ps://[Link]";
String requestBody = """
{
"customerId": 12345,
"shippingAddress": {
"line1": "Flat 101",
"line2": "Sai Residency",
"city": "Hyderabad",
"postalCode": "500081",
"country": "IN"
},
"items": [
{ "productId": "P1001", "name": "Selenium Book", "quan ty": 2, "price": 500.0 },
{ "productId": "P2001", "name": "API Tes ng Course", "quan ty": 1, "price": 1500.0 }
],
"payment": {
"method": "CARD",
"transac onId": "TXN-98765"
},
"notes": null
}
""";
Response res =
given()
.baseUri(baseUrl)
.basePath("/orders")
.contentType([Link])
.accept([Link])
.header("Authoriza on", "Bearer dummyToken123")
.body(requestBody)
.log().all()
.when()
.post()
.then()
.log().all()
.statusCode(201)
.body("status", equalTo("PLACED"))
.body("[Link]", equalTo(12345))
.body("[Link]()", equalTo(2))
.header("Content-Type", containsString("applica on/json"))
.extract().response();
JsonPath jp = [Link]();
double totalAmount = [Link]("totalAmount");
double l1 = [Link]("items[0].lineTotal");
double l2 = [Link]("items[1].lineTotal");
[Link](totalAmount, l1 + l2);
String createdAt = [Link]("meta['created-at']");
String trackingId = [Link]("meta['@trackingId']");
[Link](createdAt);
[Link]([Link]("abc-"));
}
6.2 GET /orders/{orderId} – Complex Nested JSON
Response:
{
"orderId": "ORD-2025-0001",
"status": "PLACED",
"summary": { "itemCount": 3, "paid": true },
"items": [
{ "productId": "P1001", "name": "Selenium Book", "quan ty": 2, "tags": ["book", "tes ng"] },
{ "productId": "P2001", "name": "API Tes ng Course", "quan ty": 1, "tags": ["course", "api"] },
{ "productId": "P3001", "name": "Java Basics", "quan ty": 1, "tags": [] }
],
"shipping": {
"address": { "line1": "Flat 101", "city": "Hyderabad" },
"tracking": [
{ "status": "CREATED", " me": "2025-12-07T10:20:00Z" },
{ "status": "SHIPPED", " me": "2025-12-08T09:00:00Z" }
]
}
}
Test Code:
@Test
public void getOrder_shouldValidateComplexJson() {
String baseUrl = "h ps://[Link]";
String orderId = "ORD-2025-0001";
Response res =
given()
.baseUri(baseUrl)
.pathParam("orderId", orderId)
.log().all()
.when()
.get("/orders/{orderId}")
.then()
.log().all()
.statusCode(200)
.body("orderId", equalTo(orderId))
.body("[Link]", equalTo(3))
.body("[Link]", is(true))
.body("[Link]()", equalTo(3))
.body("items[0].tags", hasItems("book","tes ng"))
.extract().response();
JsonPath jp = [Link]();
[Link]([Link]("[Link]"), "Hyderabad");
int trackSize = [Link]("[Link]()");
String lastStatus = [Link]("[Link][" + (trackSize - 1) + "].status");
[Link](lastStatus, "SHIPPED");
int apiQty = [Link]("items.find { [Link] == 'P2001' }.quan ty");
[Link](apiQty, 1);
int tagsSizeJava = [Link]("items.find { [Link] == 'P3001' }.[Link]()");
[Link](tagsSizeJava, 0);
}
6.3 GET /customers/{customerId}/orders – Root Array
Response:
[
{ "orderId": "ORD-2025-0001", "status": "PLACED", "totalAmount": 2500.0 },
{ "orderId": "ORD-2025-0002", "status": "DELIVERED", "totalAmount": 1800.0 }
]
Test Code:
@Test
public void getCustomerOrders_rootArrayValida on() {
String baseUrl = "h ps://[Link]";
Response res =
given()
.baseUri(baseUrl)
.pathParam("customerId", 12345)
.queryParam("status", "PLACED")
.queryParam("page", 1)
.log().all()
.when()
.get("/customers/{customerId}/orders")
.then()
.log().all()
.statusCode(200)
.extract().response();
JsonPath jp = [Link]();
int size = [Link]("size()");
[Link](size >= 1);
String firstOrderId = [Link]("[0].orderId");
double firstAmount = [Link]("[0].totalAmount");
[Link](firstOrderId);
[Link](firstAmount > 0);
String deliveredOrder =
[Link]("find { [Link] == 'DELIVERED' }.orderId");
if (deliveredOrder != null) {
[Link]("Delivered order: " + deliveredOrder);
}
java.u [Link]<String> statuses = [Link]("status");
[Link]([Link]("PLACED") || [Link]("DELIVERED"));
}
If you want, next I can:
Turn this into Cucumber step defini ons (Given/When/Then in .feature + step code), or
Help you convert these notes into interview-style Q&A for API tes ng + RestAssured.