Complete API Testing Guide:
Postman, REST Assured, JSON Logic & Security
Master API testing concepts tailored for QA Engineers and SDETs. Learn HTTP methods, Postman test collections, REST Assured Java BDD code ('given().when().then()'), JSON Schema validation, and OAuth authentication.
5-Step API Testing Career Path for SDETs
Master API testing step-by-step: HTTP & REST → Postman Collections → JSON Logic → REST Assured Java Automation → API Security & CI/CD.
Step 1: HTTP & REST Basics
Master HTTP Request methods (GET, POST, PUT, DELETE), status codes (2xx, 4xx, 5xx), and headers.
Study HTTP Basics →Step 2: Postman Testing
Create Postman collections, environment variables, pre-request scripts, and test assertions.
Master Postman →Step 3: JSON & Security
JSON Schema validation, OAuth 2.0, Bearer JWT tokens, API keys, and rate limit testing.
Study JSON & Security →Step 4: REST Assured Code
Build Java REST Assured frameworks with given().when().then(), POJO serialization, and TestNG.
Step 5: SOAP vs REST & CI/CD
Compare REST vs SOAP web services and integrate Postman Newman into Jenkins CI/CD.
Explore Web Services →๐ ๏ธ Interactive API Learner & Developer Suite
Interactive HTTP Request & Header Sandbox
Select an HTTP Method and endpoint parameters below to inspect generated request headers and JSON payloads.
REST Assured Java BDD Test Code Generator
Auto-generate production REST Assured Java BDD code ('given().when().then()') with status code and JSON assertions.
HTTP Status Code Matrix & Decision Tool
Click a status code to inspect its meaning, category, and real-world QA assertion scenarios.
Timed API Testing & REST Assured Quiz
Test your real-time knowledge on HTTP methods, REST Assured BDD syntax, status codes, and authentication tokens.
Module 1: API Testing Fundamentals Explained Step-by-Step
How APIs Work in Plain English & Hinglish (Student Guide)
An API (Application Programming Interface) is a messenger that takes your request, tells a system what you want to do, and returns the response back to you. Here is the step-by-step breakdown:
1. Real-World Waiter Analogy
English: Imagine sitting at a restaurant table (Client). You look at the menu and give your order to the Waiter (API). The waiter takes your order to the Kitchen (Database/Server) and brings back your prepared meal (Response).
2. Hinglish Explanation
Hinglish: API do alag systems ke beech ka bridge (setu) hota hai. Jaise Swiggy app Zomato/Restaurant ke database se live food menu and prices laane ke liye API call karta hai!
3. Why We Test APIs First
Why API Testing?: API testing happens at the Business Logic Layer (without browser UI). Tests run 10x to 100x faster, enabling early defect detection in Agile sprints!
Step-by-Step API Request & Response Lifecycle
(Sends HTTP Request + Headers + Body)
(Authenticates Bearer Token & Validates JSON)
(Returns Status Code 200 + JSON Response)
3. Difference between Query Parameters and Path Parameters?
Hinglish: Path param URL ka hi hissa hota hai; Query param ? ke baad lagaya jata hai filter aur sorting ke liye.
3. Difference between PUT and PATCH?
Hinglish: PUT poora badal deta hai; PATCH thoda sa part badalta hai (like sirf phone number).
2. How to test an API that has no documentation?
Hinglish: Proxy tools use karke ye pata lagao ki UI kaunsi calls kar raha hai.
3. What is 'API Mocking'?
Hinglish: Asli API banne se pehle uski nakal (fake API) banana testing ke liye.
4. Difference between 401 Unauthorized and 403 Forbidden?
Hinglish: 401 matlab user login nahi hai; 403 matlab login toh hai par use ye dekhne ki ijazat nahi hai.
5. What is 'Contract Testing' in API?
Hinglish: Ye check karna ki Client aur Server dono response format (keys/types) pe agree kar rahe hain.
5. Describe a challenging situation with developers or deadlines and how you handled it.
7. How to raise a defect in Jira tool?
- Click on Create Issue.
- Select Issue Type as Bug.
- Enter Summary and Description.
- Add exact Steps to Reproduce.
- Mention Expected and Actual Result.
- Attach screenshots/logs.
- Click Submit.
8. What is UNION in SQL?
Hinglish: UNION ek SQL operator hai jo do ya zyada SELECT queries ko combine karta hai.
4. What is the difference between Idempotent and Non-Idempotent HTTP Methods?
Step-by-Step Explanation:
- Idempotent Methods (GET, PUT, DELETE, HEAD, OPTIONS): Sending the exact same request 1 time or 100 times produces the exact same server state. (e.g.
DELETE /users/10deletes user 10; subsequent deletes return 404/204 without changing server state further). - Non-Idempotent Methods (POST): Sending the exact same request 5 times creates 5 new duplicate database records!
5. What is the difference between Path Variables and Query Parameters in API Requests?
Step-by-Step Comparison:
Path Variables (/api/v1/users/{userId}): Used to identify a specific resource. Part of the URL path itself.Query Parameters (/api/v1/users?status=active&page=2): Used to filter, sort, or paginate resources. Starts after?symbol.
// REST Assured Syntax:
given()
.pathParam("userId", 101) // Path Param
.queryParam("status", "active") // Query Param
.when()
.get("/api/v1/users/{userId}");
Module 2: HTTP Protocol & REST Concepts
1. Difference between GET vs POST vs PUT vs DELETE
These are HTTP methods used to perform different operations on server:
- GET: Used to retrieve data from server (no data change)
- POST: Used to create new data
- PUT: Used to update existing data (complete update)
- DELETE: Used to delete data
- GET → Get user details
- POST → Create new user
- PUT → Update user profile
- DELETE → Delete user
โ Answer (Hinglish):
- GET → data fetch karta hai
- POST → naya data create karta hai
- PUT → data update karta hai
- DELETE → data delete karta hai
3. What is a Collection in Postman?
A Collection in Postman is a group of API requests saved together. It helps to organize APIs, reuse them, and run multiple requests in sequence.
Example: Login API, User API, Payment API → all stored in one collection.
โ Answer (Hinglish):
Collection Postman me APIs ka folder hota hai jisme multiple requests store hoti hain.
2. What is Postman and what are its core features?
Hinglish: Postman API testing ka best tool hai jisme requests save karne (Collections) aur test script likhne ke features hain.
4. What are Global, Collection, and Environment variables in Postman?
Hinglish: Global har jagah apply hote hain; Environment sirf chune gaye mode (QA/Prod) pe; Collection sirf us group pe.
5. How to automate tests in Postman?
pm.test() function).Hinglish: Postman ke "Tests" tab mein JS script likh kar assertions/checks lagaye ja sakte hain.
2. Difference between GET and POST?
Hinglish: GET data laata hai aur URL mein dikhta hai; POST data bhejne ke liye hota hai aur jyadatar body mein hidden hota hai.
5. What is 'Idempotency' in API methods?
Hinglish: Agar method baar-baar chalane pe same result de toh wo idempotent hai (jaise PUT ya DELETE).
6. How to handle OAuth 2.0 Authentication in REST Assured?
Step-by-Step BDD Code Example:
First fetch the access token from the token endpoint, then pass it using oauth2() header authentication:
// Step 1: Fetch Access Token
String token = given()
.formParam("grant_type", "client_credentials")
.formParam("client_id", "my_client_id")
.formParam("client_secret", "my_secret")
.when()
.post("https://auth.example.com/oauth/token")
.then()
.extract().path("access_token");
// Step 2: Use Token in API Request
given()
.auth().oauth2(token) // Applies Bearer Header!
.when()
.get("/api/v1/secure-dashboard")
.then()
.statusCode(200);
7. What is JSON Schema Validation and how do you implement it in REST Assured?
Step-by-Step Explanation: JSON Schema validation ensures the response body adheres to expected data types (String, Number, Boolean) and mandatory key structures, preventing broken API contracts.
// REST Assured JSON Schema Assertion
given()
.get("/api/v1/users/10")
.then()
.assertThat()
.body(matchesJsonSchemaInClasspath("user-schema.json"));
Module 3: JSON Schema & API Security
4. What is API chaining in Postman?
API chaining means passing data from one API response to another API request.
Example:
- Login API → returns token
- Use same token in next API (Get User)
pm.environment.set("token", pm.response.json().token);
โ
Answer (Hinglish):Ek API ka response dusri API me use karna → API chaining.
6. How do you test APIs using Postman?
- Open Postman
- Select method (GET/POST etc.)
- Enter API URL
- Add headers (if needed)
- Add body (for POST/PUT)
- Click Send
- Validate response using tests
{
"name": "Ram",
"email": "ram@test.com"
}
โ
Answer (Hinglish):Postman open karo, method aur URL enter karo, header/body add karke Send click karo, phir response check karo.
1. What is an API and why is it tested?
Hinglish: API do softwares ke beech pul ka kaam karti hai. Iska test data aur logic check karne ke liye hota hai.
1. What is JSON and why it is preferred over XML?
Hinglish: JSON halka aur fast hota hai, aur iska code padhne mein XML se aasan hai.
2. How do you handle Authentication in APIs?
Authorization: Bearer <token>, API Keys, or Basic Auth (Username:Password).Hinglish: Header mein token ya keys daal kar user ki pehchan process ki jati hai.
3. Explain OAuth 2.0 briefly.
Hinglish: Bina password bataye permission lene ka tareeka (เคเฅเคธเฅ Login with Google).
4. What is 'Payload' and 'Headers'?
Hinglish: Payload asli data hota hai; Header request ke baare mein informatio hoti hai.
5. What are common API security risks?
Hinglish: API hacking ki threats jaise purana login use karna ya galti se security gaps chodh dena.
1. What is Microsoft Graph API?
Hinglish: Microsoft Graph API ek REST API hai jo Microsoft provide karta hai. Iska use karke hum Microsoft ke different services jaise Outlook, OneDrive, Teams aur Azure Active Directory ka data ek hi endpoint se access aur manage kar sakte hain. Ye ek central gateway ki tarah kaam karta hai aur secure authentication ke liye OAuth 2.0 use karta hai.
6. How to handle large JSON responses?
Hinglish: JSON Path use karke sirf kaam ki cheezein pick karo pure response ko padhne ke bajaye.
4. Tell me about a time you identified a critical bug through automation.
5. What is Serialization and Deserialization in API Automation?
Step-by-Step Explanation:
- Serialization: Converting a Java POJO (Plain Old Java Object) into a JSON/XML payload string before sending the HTTP request.
- Deserialization: Converting the returned JSON response string back into a Java POJO object for easy getters/assertions.
// Serialization (POJO -> JSON)
UserPOJO user = new UserPOJO("John", "SDET");
given().body(user).post("/api/users");
// Deserialization (JSON -> POJO)
UserPOJO responseUser = given().get("/api/users/1").as(UserPOJO.class);
System.out.println(responseUser.getName());
Module 4: Scenario-Based API Testing Q&As
2. Different types of status codes
Status codes show server response status:
- 1xx → Informational
- 2xx → Success (200 OK, 201 Created)
- 3xx → Redirection
- 4xx → Client error (400 Bad Request, 401 Unauthorized, 404 Not Found)
- 5xx → Server error (500 Internal Server Error)
โ Answer (Hinglish):
- 2xx → success
- 4xx → client ki mistake
- 5xx → server ki problem
5. How do you validate whether the correct response is coming or not?
We validate response by checking:
- Status code (e.g., 200 OK)
- Response body (expected data)
- Response time
- Headers
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
โ
Answer (Hinglish):Check karte hain: Status code, Response data, Time, aur Headers.
1. Explain HTTP Status Codes (2xx, 3xx, 4xx, 5xx).
- 2xx: Success (200 OK, 201 Created).
- 3xx: Redirection (301 Moved).
- 4xx: Client Error (400 Bad Request, 401 Unauthorized, 404 Not Found).
- 5xx: Server Error (500 Internal Server Error).
Module 5: SOAP vs REST Web Services
4. What are RESTful Web Services constraints?
Hinglish: REST ke kuch rules hain (Stateless etc.) jisse ye flexible aur scalable banti hain.
1. What is a web service?
Hinglish: Web service ek interface hota hai jo do different applications ke beech internet ke through data exchange karne deta hai.
2. What is the difference between SOAP and REST web services?
- REST: Lightweight, supports JSON and XML, simpler and faster, no WSDL required.
- SOAP: XML-based, heavy, uses WSDL, complex but highly secure.
Hinglish: SOAP XML-based aur heavy hota hai, jabki REST lightweight hota hai aur JSON/XML support karta hai. SOAP WSDL use karta hai, REST nahi karta.
<soap:Header/>
<soap:Body>
<GetUser>
<id>101</id>
</GetUser>
</soap:Body>
</soap:Envelope>
"id": 101,
"name": "Ram",
"role": "QA Lead"
}
| Feature | REST | SOAP |
|---|---|---|
| Protocol vs Style | Architectural Style | Protocol |
| Data Format | JSON, XML, HTML, Text | Only XML |
| Performance | Fast, lightweight | Slow, heavy payload |
3. What is WSDL and what does it contain?
Hinglish: Ye ek XML file hoti hai jo web service ke operations, request-response format aur endpoint batati hai.
6. Explain about your current project?
Hinglish: Mera current project ek web-based application hai. Mera role test cases design karna, manual testing karna aur Selenium Java se regression test cases automate karna hai.