Rest Assured
Rest Assured
2. 2 tier architecture:
In this we have a dedicated connection between the output (Client)
and the server in which the client will accept the input and displays
the output keeping the processor at a specific place.
3. 3 tier architecture: In this we have 3 different layers called as
Presentation layer which handles the input provided by the user and
displays the output which it receives from the application layer.
In Application we have all the business logic through which we can
validate the data from the presentation layer and validate the same
to send it ahead for data layer. Data layer is the place where we
manage and store the data into the data base
Components of request:
To download the postman: https://www.postman.com/downloads/
</dependencies>
@Test
public void getListOfUsers()
{
// define the baseURI
RestAssured.baseURI = "https://reqres.in";
// defining the pre requisite in order to
send the data from request
RequestSpecification reqSpecification =
RestAssured.given();
// defining the action to send the request
with request type
RequestSpecification req =
reqSpecification.when();
String strResponse =
response.asPrettyString();
System.out.println(strResponse);
Output:
SLF4J: See
http://www.slf4j.org/codes.html#StaticLoggerBinder
for further details.
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "[email protected]",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/faces/7-
image.jpg"
},
{
"id": 8,
"email": "[email protected]",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/faces/8-
image.jpg"
},
{
"id": 9,
"email": "[email protected]",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/faces/9-
image.jpg"
},
{
"id": 10,
"email": "[email protected]",
"first_name": "Byron",
"last_name": "Fields",
"avatar":
"https://reqres.in/img/faces/10-image.jpg"
},
{
"id": 11,
"email": "[email protected]",
"first_name": "George",
"last_name": "Edwards",
"avatar":
"https://reqres.in/img/faces/11-image.jpg"
},
{
"id": 12,
"email": "[email protected]",
"first_name": "Rachel",
"last_name": "Howell",
"avatar":
"https://reqres.in/img/faces/12-image.jpg"
}
],
"support": {
"url": "https://contentcaddy.io?
utm_source=reqres&utm_medium=json&utm_campaign=referr
al",
"text": "Tired of writing endless social
media content? Let Content Caddy generate it for
you."
}
}
.when()
.get("api/users?page=2");
System.out.println(strResponse);
Output:
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "[email protected]",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/faces/7-
image.jpg"
},
{
"id": 8,
"email": "[email protected]",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/faces/8-
image.jpg"
},
{
"id": 9,
"email": "[email protected]",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/faces/9-
image.jpg"
},
{
"id": 10,
"email": "[email protected]",
"first_name": "Byron",
"last_name": "Fields",
"avatar":
"https://reqres.in/img/faces/10-image.jpg"
},
{
"id": 11,
"email": "[email protected]",
"first_name": "George",
"last_name": "Edwards",
"avatar":
"https://reqres.in/img/faces/11-image.jpg"
},
{
"id": 12,
"email": "[email protected]",
"first_name": "Rachel",
"last_name": "Howell",
"avatar":
"https://reqres.in/img/faces/12-image.jpg"
}
],
"support": {
"url": "https://contentcaddy.io?
utm_source=reqres&utm_medium=json&utm_campaign=referr
al",
"text": "Tired of writing endless social
media content? Let Content Caddy generate it for
you."
}
}
Simplest Approach:
import org.testng.annotations.Test;
import io.restassured.response.Response;
public class SimplestApproach {
@Test
public void getListOfUsers()
{
baseURI = "https://reqres.in";
Response resp =
given() .when() .get("api/users?page=2");
System.out.println(strResponse);
}
Output:
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "[email protected]",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/faces/7-
image.jpg"
},
{
"id": 8,
"email": "[email protected]",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/faces/8-
image.jpg"
},
{
"id": 9,
"email": "[email protected]",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/faces/9-
image.jpg"
},
{
"id": 10,
"email": "[email protected]",
"first_name": "Byron",
"last_name": "Fields",
"avatar":
"https://reqres.in/img/faces/10-image.jpg"
},
{
"id": 11,
"email": "[email protected]",
"first_name": "George",
"last_name": "Edwards",
"avatar":
"https://reqres.in/img/faces/11-image.jpg"
},
{
"id": 12,
"email": "[email protected]",
"first_name": "Rachel",
"last_name": "Howell",
"avatar":
"https://reqres.in/img/faces/12-image.jpg"
}
],
"support": {
"url": "https://contentcaddy.io?
utm_source=reqres&utm_medium=json&utm_campaign=referr
al",
"text": "Tired of writing endless social
media content? Let Content Caddy generate it for
you."
}
}
Code structure:
.when()
.get("api/users/2")
.then()
.extract()// to extract the properties of
response
.response();
System.out.println(strResp);
Output:
{
"data": {
"id": 2,
"email": "[email protected]",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-
image.jpg"
},
"support": {
"url": "https://contentcaddy.io?
utm_source=reqres&utm_medium=json&utm_campaign=referr
al",
"text": "Tired of writing endless social
media content? Let Content Caddy generate it for
you."
}
}
Status code is 200
Example for POST :
@Test
public void creatingUser()
{
baseURI = "https://reqres.in";
.header("Content-Type", "application/json")
.body("{\r\n"
+
" \"name\": \"att23novRestassured\",\r\n"
+ " \"job\": \"learner\"\r\n"
+ "}")
.when()
.post("/api/users")
.then()
.extract()
.response();
System.out.println(strResp);
System.out.println(stsCode);
Output:
SLF4J: See
http://www.slf4j.org/codes.html#StaticLoggerBinder
for further details.
{
"name": "att23novRestassured",
"job": "learner",
"id": "31",
"createdAt": "2024-12-26T15:06:59.210Z"
}
201
@Test
public void creatingUser()
{
baseURI = "https://petstore.swagger.io/v2";
.header("Content-Type", "application/json")
.body("{\r\n"
+ " \"id\": 0,\r\n"
+
" \"username\": \"restassureduser\",\r\n"
+ " \"firstName\": \"Tom\",\r\n"
+ " \"lastName\": \"aveston\",\r\n"
+
" \"email\": \"[email protected]\",\r\n"
+ " \"password\": \"Test@1234\",\r\
n"
+ " \"phone\": \"9876543212\",\r\n"
+ " \"userStatus\": 0\r\n"
+ "}")
.when()
.post("/user")
.then()
.extract()
.response();
System.out.println(strResp);
System.out.println(stsCode);
Output:
{
"code": 200,
"type": "unknown",
"message": "9223372036854760484"
}
200
Assignment:
https://petstore.swagger.io/#/user/getUserByName
@Test
public void getUserDetails() {
baseURI = "https://petstore.swagger.io/v2";
.when()
.get("/user/Eveningtestuser")
.then()
.extract()
.response();
System.out.println(responseData);
}
Output:
{
"id": 9223372036854758843,
"username": "Eveningtestuser",
"firstName": "Alex",
"lastName": "smith",
"email": "[email protected]",
"password": "Test@1234",
"phone": "9876543211",
"userStatus": 0
}
.when()
.get("api/users?page=2")
.then()
.extract()
.response();
List<Header> listOfHeader =
allHeaders.asList();
System.out.println(number);
String valueOfHeader =
resp.getHeader("Content-Type");
System.out.println(valueOfHeader);
Output:
Value of status code is 200
Status line is HTTP/1.1 200 OK
Response time is 2342
Date=Fri, 27 Dec 2024 14:53:40 GMT
Content-Type=application/json; charset=utf-8
Transfer-Encoding=chunked
Connection=keep-alive
Report-To={"group":"heroku-
nel","max_age":3600,"endpoints":[{"url":"https://
nel.heroku.com/reports?ts=1735310137&sid=c4c9725f-
1ab0-44d8-820f-
430df2718e11&s=Yg7JOOFgS7kcs3fRcEgaTly18V9uwRrYRVgcs9
xSkXA%3D"}]}
Reporting-Endpoints=heroku-nel=https://
nel.heroku.com/reports?ts=1735310137&sid=c4c9725f-
1ab0-44d8-820f-
430df2718e11&s=Yg7JOOFgS7kcs3fRcEgaTly18V9uwRrYRVgcs9
xSkXA%3D
Nel={"report_to":"heroku-
nel","max_age":3600,"success_fraction":0.005,"failure
_fraction":0.05,"response_headers":["Via"]}
X-Powered-By=Express
Access-Control-Allow-Origin=*
Etag=W/"440-ZjsmMKR8P3usr2uJZbOCGCxC3Uw"
Via=1.1 vegur
Cache-Control=max-age=14400
CF-Cache-Status=HIT
Age=1083
Vary=Accept-Encoding
Server=cloudflare
CF-RAY=8f8a2435bb484910-BOM
Content-Encoding=gzip
server-timing=cfL4;desc="?
proto=TCP&rtt=11231&min_rtt=9585&rtt_var=4770&sent=7&
recv=7&lost=0&retrans=0&sent_bytes=3107&recv_bytes=77
5&delivery_rate=441940&cwnd=246&unsent_bytes=0&cid=64
2019968b39b392&ts=679&x=0"
19
Date=Fri, 27 Dec 2024 14:53:40 GMT
Content-Type=application/json; charset=utf-8
Transfer-Encoding=chunked
Connection=keep-alive
Report-To={"group":"heroku-
nel","max_age":3600,"endpoints":[{"url":"https://
nel.heroku.com/reports?ts=1735310137&sid=c4c9725f-
1ab0-44d8-820f-
430df2718e11&s=Yg7JOOFgS7kcs3fRcEgaTly18V9uwRrYRVgcs9
xSkXA%3D"}]}
Reporting-Endpoints=heroku-nel=https://
nel.heroku.com/reports?ts=1735310137&sid=c4c9725f-
1ab0-44d8-820f-
430df2718e11&s=Yg7JOOFgS7kcs3fRcEgaTly18V9uwRrYRVgcs9
xSkXA%3D
Nel={"report_to":"heroku-
nel","max_age":3600,"success_fraction":0.005,"failure
_fraction":0.05,"response_headers":["Via"]}
X-Powered-By=Express
Access-Control-Allow-Origin=*
Etag=W/"440-ZjsmMKR8P3usr2uJZbOCGCxC3Uw"
Via=1.1 vegur
Cache-Control=max-age=14400
CF-Cache-Status=HIT
Age=1083
Vary=Accept-Encoding
Server=cloudflare
CF-RAY=8f8a2435bb484910-BOM
Content-Encoding=gzip
server-timing=cfL4;desc="?
proto=TCP&rtt=11231&min_rtt=9585&rtt_var=4770&sent=7&
recv=7&lost=0&retrans=0&sent_bytes=3107&recv_bytes=77
5&delivery_rate=441940&cwnd=246&unsent_bytes=0&cid=64
2019968b39b392&ts=679&x=0"
application/json; charset=utf-8
Example:
public class DataExtractionFromBody1 {
@Test
public void creatingUser()
{
baseURI = "https://petstore.swagger.io/v2";
.header("Content-Type", "application/json")
.body("{\r\n"
+ " \"id\": 0,\r\n"
+ " \"username\": \"27DecUser\",\r\
n"
+ " \"firstName\": \"Tom\",\r\n"
+ " \"lastName\": \"aveston\",\r\n"
+
" \"email\": \"[email protected]\",\r\n"
+ " \"password\": \"Test@1234\",\r\
n"
+ " \"phone\": \"9876543212\",\r\n"
+ " \"userStatus\": 0\r\n"
+ "}")
.when()
.post("/user")
.then()
.extract()
.response();
System.out.println(strResp);
JsonPath jp = resp.jsonPath();
System.out.println(messageValue);//
9223372036854759463
System.out.println(codeValue);//200
Assert.assertEquals(codeValue, 200);
}
}
Output:
{
"code": 200,
"type": "unknown",
"message": "9223372036854759463"
}
9223372036854759463
200
Assignment:
WAP to create the user using Create user API and then
using get API validate the firstname of the user
Solution:
@Test
public void createUser()
{
baseURI = "https://petstore.swagger.io/v2";
.header("Content-Type",
"application/json")
.body("{\r\n"
+ " \"id\": 0,\r\n"
+
" \"username\": \"restassureduser2\",\r\n"
+
" \"firstName\": \"David\",\r\n"
+
" \"lastName\": \"aveston\",\r\n"
+
" \"email\": \"[email protected]\",\r\n"
+
" \"password\": \"Test@1234\",\r\n"
+
" \"phone\": \"9876543212\",\r\n"
+ " \"userStatus\": 0\r\n"
+ "}")
.when()
.post("/user")
.then()
.extract()
.response();
System.out.println(strResp);
@Test
public void getDetails()
{
baseURI = "https://petstore.swagger.io/v2";
.when()
.get("/user/restassureduser2")
.then()
.extract()
.response();
JsonPath jp = resp.jsonPath();
System.out.println(firstName);
Assert.assertEquals(firstName, "David");
Output:
{
"code": 200,
"type": "unknown",
"message": "9223372036854757527"
}
{
"id": 9223372036854757527,
"username": "restassureduser2",
"firstName": "David",
"lastName": "aveston",
"email": "[email protected]",
"password": "Test@1234",
"phone": "9876543212",
"userStatus": 0
}
David
Example 2:
@Test
public void getUserDetails()
{
RestAssured.baseURI = "https://reqres.in/";
.when()
.get("api/users/2")
.then()
.extract()
.response();
System.out.println(strResp);
JsonPath jp = resp.jsonPath();
System.out.println(textValue);
Output:
{
"data": {
"id": 2,
"email": "[email protected]",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-
image.jpg"
},
"support": {
"url": "https://contentcaddy.io?
utm_source=reqres&utm_medium=json&utm_campaign=referr
al",
"text": "Tired of writing endless social
media content? Let Content Caddy generate it for
you."
}
}
Tired of writing endless social media content? Let
Content Caddy generate it for you.
@Test
public void getDataFromArray()
{
RestAssured.baseURI = "https://reqres.in/";
.when()
.get("api/users?page=2")
.then()
.extract()
.response();
System.out.println(stringResp);
JsonPath jp = resp.jsonPath();
String fName =
jp.getString("data[0].first_name");
System.out.println(fName);
System.out.println(zerothIndex);
int numberOfElementsPresentInArray =
jp.getInt("data.size()");// to get the size of an
array
}
Output:
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "[email protected]",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/faces/7-
image.jpg"
},
{
"id": 8,
"email": "[email protected]",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/faces/8-
image.jpg"
},
{
"id": 9,
"email": "[email protected]",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/faces/9-
image.jpg"
},
{
"id": 10,
"email": "[email protected]",
"first_name": "Byron",
"last_name": "Fields",
"avatar":
"https://reqres.in/img/faces/10-image.jpg"
},
{
"id": 11,
"email": "[email protected]",
"first_name": "George",
"last_name": "Edwards",
"avatar":
"https://reqres.in/img/faces/11-image.jpg"
},
{
"id": 12,
"email": "[email protected]",
"first_name": "Rachel",
"last_name": "Howell",
"avatar":
"https://reqres.in/img/faces/12-image.jpg"
}
],
"support": {
"url": "https://contentcaddy.io?
utm_source=reqres&utm_medium=json&utm_campaign=referr
al",
"text": "Tired of writing endless social
media content? Let Content Caddy generate it for
you."
}
}
Michael
[id:7, email:[email protected],
first_name:Michael, last_name:Lawson,
avatar:https://reqres.in/img/faces/7-image.jpg]
Total number of elements are: 6
String websitePath =
jp.getString("dashboard.website");
System.out.println(websitePath);
Output:
www.abc.com
Assignment:
1. Print No of courses returned by API
Solution 6:
@Test
public void getDataFromJson()
{
String json = "{\r\n"
+ "\"dashboard\": {\r\n"
+ "\"purchaseAmount\": 910,\r\n"
+ "\"website\": \"www.abc.com\"\r\n"
+ "},\r\n"
+ "\"courses\": [\r\n"
+ "{\r\n"
+ "\"title\": \"Selenium Python\",\
r\n"
+ "\"price\": 50,\r\n"
+ "\"copies\": 6\r\n"
+ "},\r\n"
+ "{\r\n"
+ "\"title\": \"Cypress\",\r\n"
+ "\"price\": 40,\r\n"
+ "\"copies\": 4\r\n"
+ "},\r\n"
+ "{\r\n"
+ "\"title\": \"RPA\",\r\n"
+ "\"price\": 45,\r\n"
+ "\"copies\": 10\r\n"
+ "}\r\n"
+ "]\r\n"
+ "}\r\n"
+ "";
String websitePath =
jp.getString("dashboard.website");
System.out.println(websitePath);
int numberOfCourse =
jp.getInt("courses.size()");
int sum = 0;
for(int i=0; i<numberOfCourse; i++)
{
int priceValue =
jp.getInt("courses["+i+"].price");
int copiesValue =
jp.getInt("courses["+i+"].copies");
int purchaseValue =
jp.getInt("dashboard.purchaseAmount");
System.out.println("purchaseValue value is :
"+purchaseValue);
Assert.assertEquals(sum, purchaseValue);
Output:
www.abc.com
Sum value is : 910
purchaseValue value is : 910
Ecommerce project:
Link: https://rahulshettyacademy.com/client/
To create an account we need to click on the register button:
@Test
public void loginToApp()
{
RestAssured.baseURI =
"https://rahulshettyacademy.com";
.body("{\r\n"
+
" \"userEmail\": \"[email protected]\",\r\n"
+
" \"userPassword\": \"Test@1234\"\r\n"
+ "}")
.header("Content-Type", "application/json")
.when()
.post("api/ecom/auth/login")
.then()
.extract()
.response();
System.out.println(strResp);
JsonPath jp = resp.jsonPath();
token = jp.getString("token");
System.out.println(token);
usrId = jp.getString("userId");
System.out.println(usrId);
@Test
public void addProductToApp()
{
String pathOfImage =
System.getProperty("user.dir")+"\\TestImage2.png";
RestAssured.baseURI =
"https://rahulshettyacademy.com";
.param("productName", "Jeans")
.param("productAddedBy", usrId)
.param("productCategory", "fashion")
.param("productSubCategory", "Trouser")
.param("productPrice", "1500")
.param("productFor", "Women")
.multiPart("productImage", file)
.header("Authorization", token)
.when()
.post("api/ecom/product/add-product")
.then()
.extract()
.response();
System.out.println(strResp);
JsonPath jp = resp.jsonPath();
productIdValue = jp.getString("productId");
}
public class PlaceOrder extends BaseData {
@Test
public void placingOrder()
{
RestAssured.baseURI =
"https://rahulshettyacademy.com";
// RestAssured.useRelaxedHTTPSValidation();
.header("Content-Type", "application/json")
.header("Authorization", token)
.body("{\r\n"
+ " \"orders\": [\r\n"
+ " {\r\n"
+ " \"country\": \"India\", \
r\n"
+
" \"productOrderedId\" : \""+productIdValue+"\
"\r\n"
+ " }\r\n"
+ " ]\r\n"
+ "}")
.when()
.post("/api/ecom/order/create-order")
.then()
.extract()
.response();
System.out.println(responseValue);
}
@Test
public void deletingProduct()
{
RestAssured.baseURI =
"https://rahulshettyacademy.com";
.header("Authorization", token)
.when()
.delete("/api/ecom/product/delete-
product/"+productIdValue)
.then()
.extract()
.response();
System.out.println(respValue);
}
public class BaseData {
hm.put("id", 0);
hm.put("username", "javaobjectuser");
hm.put("firstName", "Daniel");
hm.put("lastName", "henry");
hm.put("email", "[email protected]");
hm.put("password", "Test@1234");
hm.put("phone", "9988778655");
hm.put("userStatus", 0);
RestAssured.baseURI =
"https://petstore.swagger.io/v2";
.header("Content-Type", "application/json")
.body(hm)
.log().all()
.when()
.post("/user")
.then()
.log().all()
.extract()
.response();
System.out.println(strResp);
}
Output:
Request method: POST
Request URI: https://petstore.swagger.io/v2/user
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Content-Type=application/json
Cookies: <none>
Multiparts: <none>
Body:
{
"id": 0,
"username": "javaobjectuser",
"firstName": "Daniel",
"lastName": "henry",
"email": "[email protected]",
"password": "Test@1234",
"phone": "9988778655",
"userStatus": 0
}
HTTP/1.1 200 OK
Date: Fri, 03 Jan 2025 14:22:36 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Headers: Content-Type, api_key,
Authorization
Server: Jetty(9.2.9.v20150224)
{
"code": 200,
"type": "unknown",
"message": "9223372036854775807"
}
{
"code": 200,
"type": "unknown",
"message": "9223372036854775807"
}
First request curl (Only copy the highlighted content and paste it in
the postman:
zerothElement.put("id", "1000");
zerothElement.put("type", "grains");
firstElement.put("id", "1001");
firstElement.put("type", "beverage");
mainObject.add(zerothElement);
mainObject.add(firstElement);
RestAssured.baseURI = "https://82ac28ee-c468-
42d4-b652-5ac5aed990f8.mock.pstmn.io";
given()
.header("Content-Type", "application/json")
.header("x-mock-match-request-body", "true")
.body(mainObject)
.log().all()
.when()
.post("att23eveningpostcall")
.then()
.log().all()
.extract()
.response();
Output:
Request method: POST
Request URI: https://82ac28ee-c468-42d4-b652-
5ac5aed990f8.mock.pstmn.io/att23eveningpostcall
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: x-mock-match-request-body=true
Accept=*/*
Content-Type=application/json
Cookies: <none>
Multiparts: <none>
Body:
[
{
"id": "1000",
"type": "grains"
},
{
"id": "1001",
"type": "beverage"
}
]
HTTP/1.1 200 OK
Date: Fri, 03 Jan 2025 15:11:29 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 60
Connection: keep-alive
x-srv-trace: v=1;t=42e90dd62bc845c2
x-srv-span: v=1;s=b7a2ba339a2d41f7
Access-Control-Allow-Origin: *
X-RateLimit-Limit: 120
X-RateLimit-Remaining: 119
X-RateLimit-Reset: 1735915515
ETag: W/"a4-7hO0T/XLq3TuFViTu2ZVQQdIY+A"
Vary: Accept-Encoding
{
"Message": "Request body matched with the
example"
}
Assignment:
WAP to create the java object for this json:
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": [
5, 9
], "type": "Chocolate" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" }
]}
batterHashMap1.put("id", "1001");
batterHashMap1.put("type", "Regular");
batterHashMap2.put("id", arrayOfId);
batterHashMap2.put("type", "Chocolate");
batterArray.add(batterHashMap1);
batterArray.add(batterHashMap2);
// batters json
HashMap<String, List<HashMap<String,
Object>>> batterHashMap = new HashMap<String,
List<HashMap<String, Object>>>();
batterHashMap.put("batter", batterArray);
// topping array
zerothIndex.put("id", "5001");
zerothIndex.put("type", "None");
firstIndex.put("id", "5002");
firstIndex.put("type", "Glazed");
secondIndex.put("id", "5005");
secondIndex.put("type", "Sugar");
mainObject.put("id", "0001");
mainObject.put("type", "donut");
mainObject.put("name", "Cake");
mainObject.put("ppu", 0.55);
mainObject.put("batters", batterHashMap);
mainObject.put("topping", toppingArray);
RestAssured.baseURI = "https://82ac28ee-c468-
42d4-b652-5ac5aed990f8.mock.pstmn.io";
given()
.header("x-mock-match-request-body", "true")
.header("Content-Type", "application/json")
.log().all()
.body(mainObject)
.when()
.post("att23novcomplexjson")
.then()
.log().all()
.extract()
.response();
Output:
Request method: POST
Request URI: https://82ac28ee-c468-42d4-b652-
5ac5aed990f8.mock.pstmn.io/att23novcomplexjson
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: x-mock-match-request-body=true
Accept=*/*
Content-Type=application/json
Cookies: <none>
Multiparts: <none>
Body:
{
"ppu": 0.55,
"batters": {
"batter": [
{
"id": "1001",
"type": "Regular"
},
{
"id": [
5,
9
],
"type": "Chocolate"
}
]
},
"name": "Cake",
"id": "0001",
"type": "donut",
"topping": [
{
"id": "5001",
"type": "None"
},
{
"id": "5002",
"type": "Glazed"
},
{
"id": "5005",
"type": "Sugar"
}
]
}
HTTP/1.1 201 Created
Date: Tue, 07 Jan 2025 14:46:10 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 60
Connection: keep-alive
x-srv-trace: v=1;t=d30481c4e4d1e295
x-srv-span: v=1;s=406be2cfe30508d1
Access-Control-Allow-Origin: *
X-RateLimit-Limit: 120
X-RateLimit-Remaining: 119
X-RateLimit-Reset: 1735917814
ETag: W/"96-S/5iQ2y1qqIInh5BwoPc+chvDJU"
Vary: Accept-Encoding
{
"Message": "Request body matched with the
example"
}
Example:
Pojo class: Pojo class is an abbreviation of plain old java object which
contains the getter and setter methods along with the variables
which are private and called inside the methods.
It is used to define the structure of the json.
Request:
@Test
public void createUser()
{
CreateUserRequestBody mainObj = new
CreateUserRequestBody();
mainObj.setId(0);
mainObj.setUsername("serialized_user2");
mainObj.setFirstName("Daniel");
mainObj.setLastName("Lawson");
mainObj.setEmail("[email protected]");
mainObj.setPassword("Test@1234");
mainObj.setPhone("9876543610");
mainObj.setUserStatus(0);
RestAssured.baseURI =
"https://petstore.swagger.io/v2";
.header("Content-Type", "application/json")
.body(mainObj)
.log().all()
.when()
.post("user")
.then()
.log().all()
.extract()
.response();
CreateUserResponseBody responseObject =
resp.as(CreateUserResponseBody.class);
String messageValue =
responseObject.getMessage();
System.out.println("Message value is
"+messageValue);
Output:
Request method: POST
Request URI: https://petstore.swagger.io/v2/user
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Content-Type=application/json
Cookies: <none>
Multiparts: <none>
Body:
{
"id": 0,
"username": "serialized_user2",
"firstName": "Daniel",
"lastName": "Lawson",
"email": "[email protected]",
"password": "Test@1234",
"phone": "9876543610",
"userStatus": 0
}
HTTP/1.1 200 OK
Date: Wed, 08 Jan 2025 14:51:31 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Headers: Content-Type, api_key,
Authorization
Server: Jetty(9.2.9.v20150224)
{
"code": 200,
"type": "unknown",
"message": "9223372036854771941"
}
Code value is :200
Message value is 9223372036854771941
Example 2:
Pojo class for get list of users:
}
public class Support {
}
@Test
public void getListOfUsers()
{
RestAssured.baseURI = "https://reqres.in/";
.when()
.get("api/users?page=2")
.then()
.extract()
.response();
GetListOfUsersResponseBody responseObject =
resp.as(GetListOfUsersResponseBody.class);
Integer totalValue =
responseObject.getTotal();
}
Output:
Total value from response body is : 12
Solution:
public void getListOfUsers()
{
RestAssured.baseURI =
"https://reqres.in/";
.when()
.get("api/users?page=2")
.then()
.extract()
.response();
GetListOfUsersResponseBody
responseObject =
resp.as(GetListOfUsersResponseBody.class);
Integer totalValue =
responseObject.getTotal();
List<Data> dataObject =
responseObject.getData();
Data firstIndex = dataObject.get(1);
String lastnameOfFirstIndex =
firstIndex.getLast_name();
System.out.println(lastnameOfFirstIndex);
Support supportObject =
responseObject.getSupport();
System.out.println(urlValue);
}
Output:
Total value from response body is : 12
Ferguson
https://contentcaddy.io?
utm_source=reqres&utm_medium=json&utm_campaign=referr
al
Assignment :
WAP to send the below json as a java object using
pojo class:
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters": {
"batter": [
{
"id": "1001",
"type": "Regular"
},
"id": [
5,
],
"type": "Chocolate"
},
"topping": [
"id": "5001",
"type": "None"
},
"id": "5002",
"type": "Glazed"
},
"id": "5005",
"type": "Sugar"
ResponseSpecification responseSpecification;
@BeforeClass
public void initRequestAndResponseSpecBuilder() {
RequestSpecBuilder requestSpecBuilder = new
RequestSpecBuilder();
requestSpecBuilder.setBaseUri("https://petstore.swagg
er.io");
requestSpecBuilder.setBasePath("/v2");
requestSpecBuilder.addHeader("Content-Type",
"application/json");
requestSpecBuilder.log(LogDetail.ALL);
requestSpecification =
requestSpecBuilder.build();
responseSpecBuilder.expectContentType(ContentType.JSO
N);
responseSpecBuilder.expectStatusCode(200);
responseSpecBuilder.log(LogDetail.ALL);
responseSpecification =
responseSpecBuilder.build();
@Test
public void createUser() {
given().spec(requestSpecification)
.when()
.post("user")
.then()
.spec(responseSpecification)
.extract()
.response();
Output:
Request method: POST
Request URI: https://petstore.swagger.io/v2/user
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Content-Type=application/json
Cookies: <none>
Multiparts: <none>
Body:
{
"id": 0,
"username": "restasssureduser",
"firstName": "Rest",
"lastName": "Assured",
"email": "[email protected]",
"password": "Test@1234",
"phone": "9876543210",
"userStatus": 0
}
HTTP/1.1 200 OK
Date: Thu, 09 Jan 2025 15:21:00 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Headers: Content-Type, api_key,
Authorization
Server: Jetty(9.2.9.v20150224)
{
"code": 200,
"type": "unknown",
"message": "9223372036854775713"
}
Example 2:
package specbuilder;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.filter.log.LogDetail;
import io.restassured.http.ContentType;
import
io.restassured.specification.RequestSpecification;
import
io.restassured.specification.ResponseSpecification;
ResponseSpecification responseSpecification;
@BeforeClass
public void initRequestAndResponseSpecBuilder() {
RequestSpecBuilder requestSpecBuilder = new
RequestSpecBuilder();
requestSpecBuilder.setBaseUri("https://petstore.swagg
er.io");
requestSpecBuilder.setBasePath("/v2");
requestSpecBuilder.addHeader("Content-Type",
"application/json");
requestSpecBuilder.log(LogDetail.ALL);
requestSpecification =
requestSpecBuilder.build();
responseSpecBuilder.expectContentType(ContentType.JSO
N);
responseSpecBuilder.expectStatusCode(200);
responseSpecBuilder.log(LogDetail.ALL);
responseSpecification =
responseSpecBuilder.build();
@Test
public void createUser() {
given(requestSpecification)
.when()
.post("user")
.then()
.spec(responseSpecification)
.extract()
.response();
{
"code": 200,
"type": "unknown",
"message": "9223372036854775744"
}
}
public class Topping {
@Test
public void sendComplexJson() {
ComplexJsonRequestBody requestBody = new
ComplexJsonRequestBody();
requestBody.setId("0001");
requestBody.setType("donut");
requestBody.setName("Cake");
requestBody.setPpu(0.55);
Batters battersObject =
requestBody.getBatters();
List<Batter> batterObject =
battersObject.getBatter();
ele1.setId("1001");
ele1.setType("Regular");
ele[0] = 5;
ele[1] = 9;
ele2.setId(ele);
ele2.setType("Chocolate");
batterObject.add(ele1);
batterObject.add(ele2);
List<Topping> toppingObject =
requestBody.getTopping();
top1.setId("5001");
top1.setType("None");
top2.setId("5002");
top2.setType("Glazed");
top3.setId("5005");
top3.setType("Sugar");
toppingObject.add(top1);
toppingObject.add(top2);
toppingObject.add(top3);
RestAssured.baseURI = "https://82ac28ee-c468-
42d4-b652-5ac5aed990f8.mock.pstmn.io";
.header("Content-Type", "application/json")
.header("x-mock-match-request-body", "true")
.body(requestBody)
.log().all()
.when()
.post("att23novcomplexjson")
.then()
.log().all()
.extract()
.response();
ResponseBody respBody =
finalResp.as(ResponseBody.class);
System.out.println(respMessage);
Output:
Request method: POST
Request URI: https://82ac28ee-c468-42d4-b652-
5ac5aed990f8.mock.pstmn.io/att23novcomplexjson
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: x-mock-match-request-body=true
Accept=*/*
Content-Type=application/json
Cookies: <none>
Multiparts: <none>
Body:
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters": {
"batter": [
{
"id": "1001",
"type": "Regular"
},
{
"id": [
5,
9
],
"type": "Chocolate"
}
]
},
"topping": [
{
"id": "5001",
"type": "None"
},
{
"id": "5002",
"type": "Glazed"
},
{
"id": "5005",
"type": "Sugar"
}
]
}
HTTP/1.1 201 Created
Date: Tue, 14 Jan 2025 14:11:37 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 60
Connection: keep-alive
x-srv-trace: v=1;t=d30481c4e4d1e295
x-srv-span: v=1;s=406be2cfe30508d1
Access-Control-Allow-Origin: *
X-RateLimit-Limit: 120
X-RateLimit-Remaining: 119
X-RateLimit-Reset: 1735917814
ETag: W/"96-S/5iQ2y1qqIInh5BwoPc+chvDJU"
Vary: Accept-Encoding
{
"message": "Request body matched with the
example"
}
Request body matched with the example
Example:
@Test
public void getAuthenticated()
{
RestAssured.baseURI = "https://postman-
echo.com";
.header("Authorization", "Basic
cG9zdG1hbjpwYXNzd29yZA==")
.log().all()
.when()
.get("basic-auth")
.then()
.log().all()
.extract()
.response();
// .header("Authorization", "Basic
cG9zdG1hbjpwYXNzd29yZA==")
.auth()
.basic("postman", "password")
.log().all()
.when()
.get("basic-auth")
.then()
.log().all()
.extract()
.response();
Output:
Request method: GET
Request URI: https://postman-echo.com/basic-auth
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 200 OK
Date: Tue, 14 Jan 2025 14:52:11 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 27
Connection: keep-alive
Server: nginx
ETag: W/"1b-o64KRFi1Uw+73hnrS1UFKUVInOY"
set-cookie: sails.sid=s
%3ANqZwlkLvBSBrJDVqZ4frfuJTMrU7X2dh.TTVFBi2bCNb3HOnlq
uJGrwsxaK6%2BcgpRE6XlNqcVl9k; Path=/; HttpOnly
{
"authenticated": true
}
Output:
Request method: GET
Request URI: https://postman-echo.com/basic-auth
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Authorization=Basic
cG9zdG1hbjpwYXNzd29yZA==
Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 200 OK
Date: Tue, 14 Jan 2025 14:37:43 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 27
Connection: keep-alive
Server: nginx
ETag: W/"1b-o64KRFi1Uw+73hnrS1UFKUVInOY"
set-cookie: sails.sid=s
%3AeTjWSNqbUmU968DO2K3VB0M7uaWl7k5H.a
%2FhuPqaUNHQThePQ%2Bfwz7MDMGpTobG75Btl2J12gssA;
Path=/; HttpOnly
{
"authenticated": true
}
// .header("Authorization", "Basic
cG9zdG1hbjpwYXNzd29yZA==")
.auth()
.basic("postman", "password")
.log().all()
.when()
.get("basic-auth")
.then()
.log().all()
.extract()
.response();
Output:
Request method: GET
Request URI: https://postman-echo.com/digest-auth
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 200 OK
Date: Tue, 14 Jan 2025 15:10:04 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 27
Connection: keep-alive
Server: nginx
ETag: W/"1b-o64KRFi1Uw+73hnrS1UFKUVInOY"
set-cookie: sails.sid=s
%3AClK8jNcWEmGe0IZ3afpYdU7zRftCtcvx.hquiqsgF6JdPp2BQj
Y1HbyKjoTonqaUNMKgcDeS29xA; Path=/; HttpOnly
{
"authenticated": true
}
Workspace API’s:
https://www.postman.com/postman/published-postman-
templates/folder/kua789n/workspaces
Example:
@Test
public void createWorkspace()
{
RestAssured.baseURI =
"https://api.getpostman.com";
given()
.body("{\r\n"
+ " \"workspace\": {\r\n"
+ " \"name\": \"Workspace
Two\",\r\n"
+ " \"type\": \"personal\",\
r\n"
+ " \"description\": \"This
is a test workspace\"\r\n"
+ " }\r\n"
+ "}")
.header("Content-Type", "application/json")
.header("x-api-key", "PMAK-
6787c14f646c180001649433-
4c76eb73fdf247b282c63a401c1fc62507")
.log().all()
.when()
.post("workspaces")
.then()
.log().all()
.extract()
.response();
}
Output:
Request method: POST
Request URI: https://api.getpostman.com/workspaces
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: x-api-key=PMAK-6787c14f646c180001649433-
4c76eb73fdf247b282c63a401c1fc62507
Accept=*/*
Content-Type=application/json
Cookies: <none>
Multiparts: <none>
Body:
{
"workspace": {
"name": "Workspace Two",
"type": "personal",
"description": "This is a test workspace"
}
}
HTTP/1.1 200
Date: Wed, 15 Jan 2025 14:24:15 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 82
Connection: keep-alive
Server: nginx
x-frame-options: deny
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
referrer-policy: no-referrer-when-downgrade
access-control-allow-origin: *
access-control-allow-methods: GET,POST,PUT,DELETE
access-control-allow-headers: content-type,x-api-key
access-control-allow-credentials: false
x-ratelimit-limit: 300
x-ratelimit-reset: 59
x-ratelimit-remaining: 299
ratelimit: limit=300, remaining=299, reset=59
ratelimit-policy: 300;w=60
ratelimit-limit: 300
ratelimit-remaining: 299
ratelimit-reset: 59
ratelimit-limit-month: 10000
ratelimit-remaining-month: 9994
x-ratelimit-limit-month: 10000
x-ratelimit-remaining-month: 9994
uWebSockets: 20
{
"workspace": {
"id": "d00378f4-2c58-47fb-922e-2c5116176b74",
"name": "Workspace Two"
}
}
Example 2:
@Test
public void deleteWorkspace()
{
RestAssured.baseURI =
"https://api.getpostman.com";
given()
.header("x-api-key", "PMAK-
6787c14f646c180001649433-
4c76eb73fdf247b282c63a401c1fc62507")
.log().all()
.when()
.delete("workspaces/bd441a1d-7648-410c-85d4-
04617fc22b1c")
.then()
.log().all()
.extract()
.response();
}
Output:
Request method: DELETE
Request URI:
https://api.getpostman.com/workspaces/bd441a1d-
7648-410c-85d4-04617fc22b1c
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: x-api-key=PMAK-6787c14f646c180001649433-
4c76eb73fdf247b282c63a401c1fc62507
Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 200
Date: Wed, 15 Jan 2025 14:43:20 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 59
Connection: keep-alive
Server: nginx
x-frame-options: deny
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
referrer-policy: no-referrer-when-downgrade
access-control-allow-origin: *
access-control-allow-methods: GET,POST,PUT,DELETE
access-control-allow-headers: content-type,x-api-key
access-control-allow-credentials: false
x-ratelimit-limit: 300
x-ratelimit-reset: 59
x-ratelimit-remaining: 299
ratelimit: limit=300, remaining=299, reset=59
ratelimit-policy: 300;w=60
ratelimit-limit: 300
ratelimit-remaining: 299
ratelimit-reset: 59
ratelimit-limit-month: 10000
ratelimit-remaining-month: 9991
x-ratelimit-limit-month: 10000
x-ratelimit-remaining-month: 9991
uWebSockets: 20
{
"workspace": {
"id": "bd441a1d-7648-410c-85d4-04617fc22b1c"
}
}
given()
.header("Accept",
"application/vnd.github+json")
.header("Authorization", "Bearer
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")
.header("X-GitHub-Api-Version",
"2022-11-28")
.log().all().when()
.post("user/repos")
.then()
.log().all()
.extract()
.response();
}
}
Output:
Request method: POST
Request URI: https://api.github.com/user/repos
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=application/vnd.github+json
Authorization=Bearer
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
X-GitHub-Api-Version=2022-11-28
Content-Type=text/plain;
charset=ISO-8859-1
Cookies: <none>
Multiparts: <none>
Body:
{
"name": "ATT 23Nov Repository creation test using
Restassured",
"description": "This is my test Repository",
"homepage": "https://github.com",
"private": true,
"is_template": false
}
HTTP/1.1 201 Created
Date: Thu, 16 Jan 2025 14:58:15 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 7692
Cache-Control: private, max-age=60, s-maxage=60
Vary: Accept, Authorization, Cookie, X-GitHub-
OTP,Accept-Encoding, Accept, X-Requested-With
ETag:
"5a75a3ebdbbcaf413ab506e97dc53e0ec7aa80d3ce5dd5b451a3
6f95ff948d17"
X-OAuth-Scopes: admin:enterprise, admin:gpg_key,
admin:org, admin:org_hook, admin:public_key,
admin:repo_hook, admin:ssh_signing_key, audit_log,
codespace, copilot, delete:packages, gist,
notifications, project, repo, user, workflow,
write:discussion, write:packages
X-Accepted-OAuth-Scopes: public_repo, repo
github-authentication-token-expiration: 2025-02-15
14:40:18 UTC
Location:
https://api.github.com/repos/gouravjawale100/ATT-
23Nov-Repository-creation-test-using-Restassured
X-GitHub-Media-Type: github.v3; format=json
x-github-api-version-selected: 2022-11-28
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4997
X-RateLimit-Reset: 1737042104
X-RateLimit-Used: 3
X-RateLimit-Resource: core
Access-Control-Expose-Headers: ETag, Link, Location,
Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-
RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-
Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-
Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-
Media-Type, X-GitHub-SSO, X-GitHub-Request-Id,
Deprecation, Sunset
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000;
includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Referrer-Policy: origin-when-cross-origin, strict-
origin-when-cross-origin
Content-Security-Policy: default-src 'none'
Server: github.com
X-GitHub-Request-Id: 0DB9:39DF8A:96B0:B192:67891E85
{
"id": 917737741,
"node_id": "R_kgDONrORDQ",
"name": "ATT-23Nov-Repository-creation-test-
using-Restassured",
"full_name": "gouravjawale100/ATT-23Nov-
Repository-creation-test-using-Restassured",
"private": true,
"owner": {
"login": "gouravjawale100",
}
Assertions in RestAssured @Test
public void assertData() {
{
RestAssured.baseURI =
"https://api.getpostman.com";
given()
.header("x-api-key", "PMAK-
678a64fac2307b000101ce47-
fcb1f3a2c10b29d0b9598aba98beb7a6f5")
.log().all()
.when()
.get("workspaces")
.then()
.header("Content-Type",
"application/json; charset=utf-8")
.body("workspaces[1].id",
equalTo("8e12339e-b561-4326-90db-29384205056e")) //
if a path contains specific value
.body(containsString("8e12339e-b561-
4326-90db-29384205056e")) // if complete response has
a String present
.body("workspaces[1]",
hasKey("createdBy")) // if the defined path has a
specific key then it will pass
.body("workspaces[4]", hasEntry("id",
"2a2df301-4bcb-4e1c-afa6-25ab7285104a")) // if
specific path has a valid key-value pair
.body("workspaces.name", hasItems("Test
workspaceevening","Latest workspace123"))//if the
provided values got matched then it will pass
otherwise fail
.body("workspaces.name", contains("Team
Workspace", "My Workspace", "ModifyingTest
Workspace", "ATTObjectWorkspace", "Manual Workspace",
"Latest workspace123", "ATT batch Workspace2", "Test
workspaceevening", "ATT30AugRestAssuredWorkspace",
"TestDataFromResponse", "RestAssured workspace",
"RestAssured workspace", "RestAssured workspace",
"Manually created workspace", "workspace created
through restassured", "updated ATT morning
restassured", "ATT morning restassured post request",
"workspacecreated using postman",
"ATT20JanWorkspace", "UpdatedworkspaceATT20Jan",
"ATT20RestAssuredWorkspace", "ATT20JanWorkspace3",
"latestFeb23RestAssuredWorkspace", "modified
workspace name ATT 6Apr", "Restassured workspace 29
May", "ATT11MayWorkspace by RestAssured",
"ATT11MayWorkspace by RestAssured",
"ATT11MayWorkspace by RestAssured", "Updated
ATT11MayWorkspaceLatest by Code", "Restassured
workspace 29 May", "ATT13July workspace",
"ATT13JulyWorkspace Postman", "ATT13JulyWorkspace-
RestAssured", "Manualtestingworkspacecreation",
"ATT28SeptWorkspace", "ATT28SeptWorkspaceMorning",
"ATT28SeptWorkspaceMorningByRestAssured",
"ATT28SeptWorkspaceMorningByRestAssured", "New
Workspace created manually", "New Workspace created
manually", "Workspace Two"))
// contains method will not only
check the content of all the provided names along
with the sequence of data
.body("workspaces.name",
containsInAnyOrder( "My Workspace", "ModifyingTest
Workspace", "Team Workspace", "ATTObjectWorkspace",
"Manual Workspace", "Latest workspace123", "ATT batch
Workspace2", "Test workspaceevening",
"ATT30AugRestAssuredWorkspace",
"TestDataFromResponse", "RestAssured workspace",
"RestAssured workspace", "RestAssured workspace",
"Manually created workspace", "workspace created
through restassured", "updated ATT morning
restassured", "ATT morning restassured post request",
"workspacecreated using postman",
"ATT20JanWorkspace", "UpdatedworkspaceATT20Jan",
"ATT20RestAssuredWorkspace", "ATT20JanWorkspace3",
"latestFeb23RestAssuredWorkspace", "modified
workspace name ATT 6Apr", "Restassured workspace 29
May", "ATT11MayWorkspace by RestAssured",
"ATT11MayWorkspace by RestAssured",
"ATT11MayWorkspace by RestAssured", "Updated
ATT11MayWorkspaceLatest by Code", "Restassured
workspace 29 May", "ATT13July workspace",
"ATT13JulyWorkspace Postman", "ATT13JulyWorkspace-
RestAssured", "Manualtestingworkspacecreation",
"ATT28SeptWorkspace", "ATT28SeptWorkspaceMorning",
"ATT28SeptWorkspaceMorningByRestAssured",
"ATT28SeptWorkspaceMorningByRestAssured", "New
Workspace created manually", "New Workspace created
manually", "Workspace Two"))
.body("workspaces", hasSize(41))// it
will verify if the provided size of array is equal or
not
.log().all();
}
.log().all()
.when()
.get("api/users/2")
.then()
.log().all()
.response();
{
"data": {
"id": 2,
"email": "[email protected]",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-
image.jpg"
},
"support": {
"url": "https://contentcaddy.io?
utm_source=reqres&utm_medium=json&utm_campaign=referr
al",
"text": "Tired of writing endless social
media content? Let Content Caddy generate it for
you."
}
}
.log().body()
.when()
.get("api/users/2")
.then()
.log().body()
.response();
}
Output:
Body: <none>
{
"data": {
"id": 2,
"email": "[email protected]",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-
image.jpg"
},
"support": {
"url": "https://contentcaddy.io?
utm_source=reqres&utm_medium=json&utm_campaign=referr
al",
"text": "Tired of writing endless social
media content? Let Content Caddy generate it for
you."
}
}
.log().uri()
.when()
.get("api/users/2")
.then()
.log().headers()
.response();
Output:
Request URI: https://reqres.in/api/users/2
Date: Fri, 17 Jan 2025 14:59:15 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Report-To: {"group":"heroku-
nel","max_age":3600,"endpoints":[{"url":"https://
nel.heroku.com/reports?ts=1737093901&sid=c4c9725f-
1ab0-44d8-820f-430df2718e11&s=ianbRAjXJiFBZqkHIZn
%2F54osnCDOVn75Bn7PXb2k6Ic%3D"}]}
Reporting-Endpoints:
heroku-nel=https://nel.heroku.com/reports?
ts=1737093901&sid=c4c9725f-1ab0-44d8-820f-
430df2718e11&s=ianbRAjXJiFBZqkHIZn
%2F54osnCDOVn75Bn7PXb2k6Ic%3D
Nel: {"report_to":"heroku-
nel","max_age":3600,"success_fraction":0.005,"failure
_fraction":0.05,"response_headers":["Via"]}
X-Powered-By: Express
Access-Control-Allow-Origin: *
Etag: W/"152-ApQgGHL6RKwaebFlrPCYPBO1xHg"
Via: 1.1 vegur
Cache-Control: max-age=14400
CF-Cache-Status: HIT
Age: 3250
Vary: Accept-Encoding
Server: cloudflare
CF-RAY: 903735440d9df563-BOM
Content-Encoding: gzip
server-timing: cfL4;desc="?
proto=TCP&rtt=6123&min_rtt=5917&rtt_var=2631&sent=7&r
ecv=7&lost=0&retrans=0&sent_bytes=3106&recv_bytes=770
&delivery_rate=559873&cwnd=188&unsent_bytes=0&cid=4f9
750c846de9838&ts=387&x=0"
@Test
public void getSingleUserDetail()
{
baseURI = "https://reqres.in";
.log().ifValidationFails()
.when()
.get("api/users/2")
.then()
.assertThat()
.log().headers()
.statusCode(300)
.response();
}
}
Output:
Date: Fri, 17 Jan 2025 15:04:41 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Report-To: {"group":"heroku-
nel","max_age":3600,"endpoints":[{"url":"https://
nel.heroku.com/reports?ts=1737093901&sid=c4c9725f-
1ab0-44d8-820f-430df2718e11&s=ianbRAjXJiFBZqkHIZn
%2F54osnCDOVn75Bn7PXb2k6Ic%3D"}]}
Reporting-Endpoints:
heroku-nel=https://nel.heroku.com/reports?
ts=1737093901&sid=c4c9725f-1ab0-44d8-820f-
430df2718e11&s=ianbRAjXJiFBZqkHIZn
%2F54osnCDOVn75Bn7PXb2k6Ic%3D
Nel: {"report_to":"heroku-
nel","max_age":3600,"success_fraction":0.005,"failure
_fraction":0.05,"response_headers":["Via"]}
X-Powered-By: Express
Access-Control-Allow-Origin: *
Etag: W/"152-ApQgGHL6RKwaebFlrPCYPBO1xHg"
Via: 1.1 vegur
Cache-Control: max-age=14400
CF-Cache-Status: HIT
Age: 3576
Vary: Accept-Encoding
Server: cloudflare
CF-RAY: 90373d39ea7e3b03-BOM
Content-Encoding: gzip
server-timing: cfL4;desc="?
proto=TCP&rtt=8406&min_rtt=7947&rtt_var=3900&sent=7&r
ecv=7&lost=0&retrans=0&sent_bytes=3107&recv_bytes=770
&delivery_rate=364355&cwnd=250&unsent_bytes=0&cid=774
8188b847b7b07&ts=585&x=0"
Request method: GET
Request URI: https://reqres.in/api/users/2
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
FAILED: basics.GET_ListOfUsers.getSingleUserDetail
java.lang.AssertionError: 1 expectation failed.
Expected status code <300> but was <200>.
.log().all()
.when()
.get("api/users/2/sgdadgkajsgdasgdjgsadjsa")
.then()
.assertThat()
.log().ifError()
.statusCode(200)
.response();
}
}
Output:
Request method: GET
Request URI:
https://reqres.in/api/users/2/sgdadgkajsgdasgdjgsadjs
a
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 404 Not Found
Date: Fri, 17 Jan 2025 15:12:47 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 2
Connection: keep-alive
Report-To: {"group":"heroku-
nel","max_age":3600,"endpoints":[{"url":"https://
nel.heroku.com/reports?ts=1737126767&sid=c4c9725f-
1ab0-44d8-820f-430df2718e11&s=VlKN2jWsmGo
%2FvHI7QJOnfI79Dx6n%2BavYAGObfFulPPs%3D"}]}
Reporting-Endpoints:
heroku-nel=https://nel.heroku.com/reports?
ts=1737126767&sid=c4c9725f-1ab0-44d8-820f-
430df2718e11&s=VlKN2jWsmGo%2FvHI7QJOnfI79Dx6n
%2BavYAGObfFulPPs%3D
Nel: {"report_to":"heroku-
nel","max_age":3600,"success_fraction":0.005,"failure
_fraction":0.05,"response_headers":["Via"]}
X-Powered-By: Express
Access-Control-Allow-Origin: *
Etag: W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8"
Via: 1.1 vegur
Cache-Control: max-age=14400
CF-Cache-Status: MISS
Vary: Accept-Encoding
Server: cloudflare
CF-RAY: 903749187d2646a7-BOM
server-timing: cfL4;desc="?
proto=TCP&rtt=8785&min_rtt=8507&rtt_var=3746&sent=7&r
ecv=7&lost=0&retrans=0&sent_bytes=3107&recv_bytes=795
&delivery_rate=394670&cwnd=252&unsent_bytes=0&cid=4e9
c98f078366568&ts=722&x=0"
@Test
public void getListOfUsers() {
baseURI = "https://reqres.in";
Response resp = given()
.queryParam("page", "2")
.queryParam("line", "4")
.queryParam("word", "6")
.log().all()
.when()
.get("api/users")
.then()
.log().all()
.extract()
.response();
Output:
Request method: GET
Request URI: https://reqres.in/api/users?
page=2&line=4&word=6
Proxy: <none>
Request params: <none>
Query params: page=2
line=4
word=6
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 200 OK
Date: Fri, 17 Jan 2025 15:23:41 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Report-To: {"group":"heroku-
nel","max_age":3600,"endpoints":[{"url":"https://
nel.heroku.com/reports?ts=1737127421&sid=c4c9725f-
1ab0-44d8-820f-430df2718e11&s=dd6hqzA2Zp
%2FXZv1QLUVP3AsvBkSqEhWhqK5t9YKqpm8%3D"}]}
Reporting-Endpoints:
heroku-nel=https://nel.heroku.com/reports?
ts=1737127421&sid=c4c9725f-1ab0-44d8-820f-
430df2718e11&s=dd6hqzA2Zp
%2FXZv1QLUVP3AsvBkSqEhWhqK5t9YKqpm8%3D
Nel: {"report_to":"heroku-
nel","max_age":3600,"success_fraction":0.005,"failure
_fraction":0.05,"response_headers":["Via"]}
X-Powered-By: Express
Access-Control-Allow-Origin: *
Etag: W/"440-ZjsmMKR8P3usr2uJZbOCGCxC3Uw"
Via: 1.1 vegur
Cache-Control: max-age=14400
CF-Cache-Status: MISS
Vary: Accept-Encoding
Server: cloudflare
CF-RAY: 9037590c5b2b3e15-BOM
Content-Encoding: gzip
server-timing: cfL4;desc="?
proto=TCP&rtt=7468&min_rtt=7408&rtt_var=2899&sent=7&r
ecv=7&lost=0&retrans=0&sent_bytes=3107&recv_bytes=789
&delivery_rate=536610&cwnd=250&unsent_bytes=0&cid=933
fa1e92320eddf&ts=784&x=0"
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
}
2. QueryParams() method:
@Test
public void getListOfUsers() {
baseURI = "https://reqres.in";
Response resp = given()
// .queryParam("page", "2")
//
// .queryParam("line", "4")
//
// .queryParam("word", "6")
.when()
.get("api/users")
.then()
.log().all()
.extract()
.response();
}
Output:
Request method: GET
Request URI: https://reqres.in/api/users?
page=2&line=4&word=6
Proxy: <none>
Request params: <none>
Query params: page=2
line=4
word=6
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 200 OK
Date: Fri, 17 Jan 2025 15:28:39 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Report-To: {"group":"heroku-
nel","max_age":3600,"endpoints":[{"url":"https://
nel.heroku.com/reports?ts=1737127421&sid=c4c9725f-
1ab0-44d8-820f-430df2718e11&s=dd6hqzA2Zp
%2FXZv1QLUVP3AsvBkSqEhWhqK5t9YKqpm8%3D"}]}
Reporting-Endpoints:
heroku-nel=https://nel.heroku.com/reports?
ts=1737127421&sid=c4c9725f-1ab0-44d8-820f-
430df2718e11&s=dd6hqzA2Zp
%2FXZv1QLUVP3AsvBkSqEhWhqK5t9YKqpm8%3D
Nel: {"report_to":"heroku-
nel","max_age":3600,"success_fraction":0.005,"failure
_fraction":0.05,"response_headers":["Via"]}
X-Powered-By: Express
Access-Control-Allow-Origin: *
Etag: W/"440-ZjsmMKR8P3usr2uJZbOCGCxC3Uw"
Via: 1.1 vegur
Cache-Control: max-age=14400
CF-Cache-Status: HIT
Age: 298
Vary: Accept-Encoding
Server: cloudflare
CF-RAY: 90376056b86140bd-BOM
Content-Encoding: gzip
server-timing: cfL4;desc="?
proto=TCP&rtt=8496&min_rtt=7900&rtt_var=4155&sent=7&r
ecv=7&lost=0&retrans=0&sent_bytes=3107&recv_bytes=789
&delivery_rate=334306&cwnd=252&unsent_bytes=0&cid=fcb
a4e639228341f&ts=408&x=0"
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
3. using hashmap:
@Test
public void getListOfUsers() {
LinkedHashMap<String, String> hm = new
LinkedHashMap<String, String>();
hm.put("page", "2");
hm.put("line", "4");
hm.put("word", "6");
baseURI = "https://reqres.in";
Response resp = given()
// .queryParam("page", "2")
//
// .queryParam("line", "4")
//
// .queryParam("word", "6")
.queryParams(hm)
.log().all()
.when()
.get("api/users")
.then()
.log().all()
.extract()
.response();
}
Output:
Request method: GET
Request URI: https://reqres.in/api/users?
page=2&line=4&word=6
Proxy: <none>
Request params: <none>
Query params: page=2
line=4
word=6
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 200 OK
Date: Fri, 17 Jan 2025 15:32:00 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Report-To: {"group":"heroku-
nel","max_age":3600,"endpoints":[{"url":"https://
nel.heroku.com/reports?ts=1737127421&sid=c4c9725f-
1ab0-44d8-820f-430df2718e11&s=dd6hqzA2Zp
%2FXZv1QLUVP3AsvBkSqEhWhqK5t9YKqpm8%3D"}]}
Reporting-Endpoints:
heroku-nel=https://nel.heroku.com/reports?
ts=1737127421&sid=c4c9725f-1ab0-44d8-820f-
430df2718e11&s=dd6hqzA2Zp
%2FXZv1QLUVP3AsvBkSqEhWhqK5t9YKqpm8%3D
Nel: {"report_to":"heroku-
nel","max_age":3600,"success_fraction":0.005,"failure
_fraction":0.05,"response_headers":["Via"]}
X-Powered-By: Express
Access-Control-Allow-Origin: *
Etag: W/"440-ZjsmMKR8P3usr2uJZbOCGCxC3Uw"
Via: 1.1 vegur
Cache-Control: max-age=14400
CF-Cache-Status: HIT
Age: 499
Vary: Accept-Encoding
Server: cloudflare
CF-RAY: 9037653d194740cf-BOM
Content-Encoding: gzip
server-timing: cfL4;desc="?
proto=TCP&rtt=7894&min_rtt=7599&rtt_var=3439&sent=7&r
ecv=7&lost=0&retrans=0&sent_bytes=3107&recv_bytes=789
&delivery_rate=425343&cwnd=251&unsent_bytes=0&cid=052
76e6eac57440f&ts=690&x=0"
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,}
@Test
public void getSingleUserDetail() {
baseURI = "https://reqres.in";
.pathParam("pathParam1", "2")
.pathParam("pathParam2", "4")
.pathParam("pathParam3", "6")
.log().all()
.when()
.get
("api/users/{pathParam1}/{pathParam2}/{pathParam3}")
.then()
.log().all()
.response();
}
Output:
Request method: GET
Request URI: https://reqres.in/api/users/2/4/6
Proxy: <none>
Request params: <none>
Example 2:
@Test
public void getSingleUserDetail() {
baseURI = "https://reqres.in";
// .pathParam("pathParam1", "2")
//
// .pathParam("pathParam2", "4")
//
// .pathParam("pathParam3", "6")
.pathParams("pathParam1","2",
"pathParam2", "4", "pathParam3", "6")
.log().all()
.when()
.get
("api/users/{pathParam1}/{pathParam2}/{pathParam3}")
.then()
.log().all()
.extract()// to extract the
properties of response
.response();
}
}
Output:
Request method: GET
Request URI: https://reqres.in/api/users/2/4/6
Proxy: <none>
Request params: <none>
Example 3:
@Test
public void getSingleUserDetail() {
baseURI = "https://reqres.in";
hm.put("pathParam1", "2");
hm.put("pathParam2", "3");
hm.put("pathParam3", "4");
// .pathParam("pathParam1", "2")
//
// .pathParam("pathParam2", "4")
//
// .pathParam("pathParam3", "6")
// .pathParams("pathParam1","2",
"pathParam2", "4", "pathParam3", "6")
.pathParams(hm)
.log().all()
.when()
.get
("api/users/{pathParam1}/{pathParam2}/{pathParam3}")
.then()
.log().all()
.response();
}
}
Output:
Request method: GET
Request URI: https://reqres.in/api/users/2/3/4
Proxy: <none>
JWT Token: It is a token used to transmit information
between the 2 entities for authentication ad
authorization purpose so that user can avail the
service by proving the identity using JWT token.
It has 3 parts:
1. Header – It contains the algorithm at which we had
created it.
2. Payload – contains the data to be shown to the
server so that we can display the identity.
%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3B%22%20edge%3D%221%22%20source%3D%225%22%20target%3D%228%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3B%22%20edge%3D%221%22%20source%3D%225%22%20target%3D%228%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D
%224%22%20value%3D%22%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3B%22%20edge%3D%221%22%20source%3D%225%22%20target%3D%2210%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%225%22%20value%3D%22Zoomin%20application%22%20style%3D%22rounded%3D1%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22140%22%20y%3D%2290%22%20width%3D%22120%22%20height%3D%2260%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%226%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3B%22%20edge%3D%221%22%20source
%3D%227%22%20target%3D%225%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%227%22%20value%3D%22User%22%20style%3D%22shape%3DumlActor%3BverticalLabelPosition%3Dbottom%3BverticalAlign%3Dtop%3Bhtml%3D1%3BoutlineConnect%3D0%3BfontSize%3D17%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22-90%22%20y%3D%2290%22%20width%3D%2230%22%20height%3D%2260%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%228%22%20value%3D%22Enter%20the%20data%20manually%20and%20create%20the%20account%22%20style%3D%22whiteSpace%3Dwrap%3Bhtml%3D1%3Brounded%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22320%22%20y%3D%2230%22%20width%3D
%22120%22%20height%3D%2260%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%229%22%20value%3D%22%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3B%22%20edge%3D%221%22%20source%3D%2210%22%20target%3D%2212%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2210%22%20value%3D%22Google%20app%22%20style%3D%22whiteSpace%3Dwrap%3Bhtml%3D1%3Brounded%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22320%22%20y%3D%22150%22%20width%3D%22120%22%20height%3D%2260%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2211%22%20value%3D%22%22%20style%3D%22edgeStyle
%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3B%22%20edge%3D%221%22%20source%3D%2212%22%20target%3D%2214%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2212%22%20value%3D%22Authentication%22%20style%3D%22whiteSpace%3Dwrap%3Bhtml%3D1%3Brounded%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22320%22%20y%3D%22290%22%20width%3D%22120%22%20height%3D%2260%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2213%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BentryX%3D0.351%3BentryY%3D1.027%3BentryDx%3D0%3BentryDy%3D0%3BentryPerimeter
%3D0%3B%22%20edge%3D%221%22%20source%3D%2214%22%20target%3D%225%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2214%22%20value%3D%22Permission%22%20style%3D%22whiteSpace%3Dwrap%3Bhtml%3D1%3Brounded%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22120%22%20y%3D%22290%22%20width%3D%22120%22%20height%3D%2260%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2215%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3B%22%20edge%3D%221%22%20source%3D%2216%22%20target%3D%225%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E
%3CmxCell%20id%3D%2216%22%20value%3D%22Google%20Server%22%20style%3D%22shape%3Dcylinder3%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3BboundedLbl%3D1%3BbackgroundOutline%3D1%3Bsize%3D15%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22210%22%20y%3D%22190%22%20width%3D%22100%22%20height%3D%2290%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2217%22%20value%3D%22Photos%22%20style%3D%22text%3Bhtml%3D1%3BstrokeColor%3Dnone%3BfillColor%3Dnone%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3BwhiteSpace%3Dwrap%3Brounded%3D0%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22220%22%20y%3D%22190%22%20width%3D%2260%22%20height%3D%2230%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2218%22%20value%3D
%22%26lt%3Bb%26gt%3BOATH%202.0%26amp%3Bnbsp%3B%26lt%3B%2Fb%26gt%3B%22%20style%3D%22text%3Bhtml%3D1%3BstrokeColor%3Dnone%3BfillColor%3Dnone%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3BwhiteSpace%3Dwrap%3Brounded%3D0%3BfontSize%3D16%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%2270%22%20y%3D%22360%22%20width%3D%2290%22%20height%3D%2230%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
OATH 2.0:
Terminologies:
1. Client app: The application which send the request to get on the
behalf of user.
2. Authorization server: The server will allow the client app to use
the data of the user on post granting the permission.
3. Resource: The data that is to be shared is called as Resource.
4. Auth code: After acquiring the permission from user auth server
will send the auth code(short live token to the application so that
application can request for Refresh and Access token based on the
auth code.
Flow chart for OATH 2.0
1. User will go to client app (Zoomin app) in order to consume the
services.
2. Client app will redirect the user to Authorization server.
3. Authorization server will show login screen to the user so that user
can grant the permission to auth server inorder to access the data.
4. After granting the permission the auth server will share the short
live token i.e Auth code to the client app.
Note: Here in OATH 2.0 if the in step 4 the auth code is returned by
the client app as an acknowledgement then it is called as
Authorization grant flow whereas if the acknowledgement is not
provided by client app to the auth server then it is called as Implicit
grant flow.
5. Client app will send another request to the auth server so that as a
response auth server will return the refresh token and access token.
6. Based on the received access token client app will fetch the data
on the behalf of user.
To use the OATH 2.0 create an account for spotify:
1. Go to the url: https://open.spotify.com/
2. Click on signup / login followed by filling the form and create the
account
Creation of app:
1. Go to dashboard: