0% found this document useful (0 votes)
31 views

API Chaining

The document outlines the process of API chaining using two examples: a Students API and a GoRest API. It details the steps for creating, retrieving, and deleting a student, as well as creating, retrieving, updating, and deleting a user, including the necessary request bodies and scripts for capturing and using environment variables. Additionally, it provides pre-request scripts for generating random user data and tests for validating JSON response fields.

Uploaded by

bhushan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

API Chaining

The document outlines the process of API chaining using two examples: a Students API and a GoRest API. It details the steps for creating, retrieving, and deleting a student, as well as creating, retrieving, updating, and deleting a user, including the necessary request bodies and scripts for capturing and using environment variables. Additionally, it provides pre-request scripts for generating random user data and tests for validating JSON response fields.

Uploaded by

bhushan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

API Chaining

Example1: Students API


Step1: Send Post request (create student) then collect “id” from response
https://localhost:3000/students
Request body

{
"name": "sonu",
"location": "India",
"phone": "9970573392",
"courses": [
"Html",
"Panda"
]
}

Tests
Include below script in Tests to collect id as environment variable.

//Capturing id from response


var jsonData=JSON.parse(responseBody);
pm.environment.set("id",jsonData.id);
Step2: Send Get request (display student) using for “id” captured from
previous request.
http://localhost:3000/students/{{id}}

Step3: Send Delete request (delete student) using for “id” captured from
previous request.
http://localhost:3000/students/{{id}}

Example2: GoRest API (Users)


https://gorest.co.in/
Access Token
31ba8caea7ad53bd0891d67b21a5091d01e82c246f1163c9e1720481379e
52bb
https://gorest.co.in/

POST /public/v2/users Create a new user


GET /public/v2/users/2138897 Get user details
PUT|PATCH /public/v2/users/2138897 Update user details
DELETE /public/v2/users/2138897 Delete user

Create User (Post)


{{url}}/public/v2/users

Request body

{
"name": "",
"email": "",
"gender": "female",
"status": "inactive"
}
Pre-request script for generate random mailID and random name

var random=Math.random(8).toString(2);
var useremail="jim"+random+"@gmail.com";
var username="jim"+random;
pm.environment.set("email_env",useremail);
pm.environment.set("name_env",username);
Tests
//capturing id from response & Set as envirnment variable
var jsonData=JSON.parse(responseBody);
pm.environment.set("userid_env",jsonData.id);

Get User details (Get)


{{url}}/public/v2/users/{{userid_env}}

Tests

//Validating JSON fields in Response


pm.test("values of fields in response",()=>{
var jsonData=pm.response.json();

pm.expect(jsonData.id).to.eql(pm.environment.get("userid_env")
);

pm.expect(jsonData.id).to.eql(pm.environment.get("email_env"))
;

pm.expect(jsonData.name).to.eql(pm.environment.get("name_env")
);
});

Update User details (Put)


https://gorest.co.in/public/v2/users/{{userid_env}}

Request Body

{
"name":"{{neme_env}}",
"email":"{{email_env}}",
"gender": "male",
"status": "active"
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy