API

API Fundamentals โ€“ Complete Beginner to Advanced Guide

Chapter 1: What is an API?

API stands for Application Programming Interface. It is a set of defined rules that explain how software programs communicate with each other. You can think of an API as a messenger between a client and a server that takes a request, tells the server what you want, and then delivers the response back to the client. APIs help systems talk to each other without knowing how they are implemented internally.

Chapter 2: Real-Life Analogy

Imagine you’re at a restaurant. You (the client) want to order food. The waiter (API) takes your order to the kitchen (server), and the kitchen prepares your food. The waiter then delivers your food back to your table. You never go into the kitchen or talk to the chefโ€”you just communicate through the waiter. Similarly, APIs handle communication between applications.

Chapter 3: Why APIs Matter in Testing

APIs are essential in backend systems. By testing APIs, you validate logic and data flow directly at the business layer, skipping the UI. API testing is faster, more stable, and easier to automate than UI testing. It can catch bugs early and validate integrations between systems.

Chapter 4: Types of APIs

1. REST (Representational State Transfer): The most common type, uses HTTP.
2. SOAP (Simple Object Access Protocol): Uses XML and strict rules.
3. GraphQL: A flexible query language for APIs.
4. Webhooks: Event-based APIs used to send real-time notifications.

Chapter 5: REST API Structure

REST APIs are based on resources. Each resource (like a user or post) is accessible via a URL (endpoint). They use HTTP methods to perform actions on those resources. REST is stateless, meaning each request must contain all required information.

Chapter 6: HTTP Methods (Verbs)

GET โ€“ Retrieve data
POST โ€“ Create data
PUT โ€“ Update/replace data
PATCH โ€“ Partial update
DELETE โ€“ Remove data

Chapter 7: Status Codes

These 3-digit codes indicate result of your API call:
200 โ€“ OK (Success)
201 โ€“ Created
204 โ€“ No Content (but success)
400 โ€“ Bad Request (client error)
401 โ€“ Unauthorized
403 โ€“ Forbidden
404 โ€“ Not Found
500 โ€“ Internal Server Error

Chapter 8: JSON and XML

JSON (JavaScript Object Notation) is lightweight, readable, and commonly used in REST.
Example:
{ “id”: 1, “name”: “Lok” }

XML is used more with SOAP APIs and looks like:
<user><id>1</id><name>Lok</name></user>

Chapter 9: API Parameters

– Path Parameters: `/users/123` โ†’ 123 is user ID
– Query Parameters: `/users?page=2` โ†’ used for filtering/sorting
– Headers: Meta information (e.g., Content-Type, Authorization)
– Body: The data you send in POST/PUT requests

Chapter 1: What is Postman?

Postman is a popular desktop and web application for testing APIs. It allows you to build, send, and test HTTP requests visually without needing to write code initially. It supports REST, GraphQL, and SOAP protocols and is widely used by developers and QA engineers to test APIs manually and automate tests.

Chapter 2: Installing and Launching Postman

To install Postman:
1. Go to https://www.postman.com/downloads/
2. Download the installer for your OS (Windows, Mac, Linux)
3. Install and open the application
4. Sign in with an email or Google account to save collections to the cloud.

Chapter 3: Creating and Sending Your First Request

1. Open Postman and click ‘New Request’
2. Choose GET method
3. Enter the URL: https://jsonplaceholder.typicode.com/posts/1
4. Click ‘Send’
5. You will receive a JSON response from the API, showing details of post ID 1.

Chapter 4: Understanding the Interface

Postman’s interface has the following key areas:
– Request builder (where you define method, URL, headers, body)
– Response section (status, time, size, body)
– Tests tab (write JavaScript to validate response)
– Pre-request Script tab (run JS before request)
– History and Collections for saved requests

Chapter 5: Writing Basic Tests in Postman

In the ‘Tests’ tab, use JavaScript and Postman’s pm object:
Example:
pm.test(“Status code is 200”, function () {
    pm.response.to.have.status(200);
});

Chapter 6: Using Variables and Environments

Environments help switch between dev, QA, and prod setups.
Steps:
1. Create environment โ†’ Add variables like base_url
2. Use {{base_url}} in your request URL
3. Select environment before running the request

Chapter 7: Creating and Using Collections

Collections are folders of grouped API requests.
Steps:
1. Create Collection โ†’ Add new requests
2. Apply shared authorization, scripts, headers at the folder level
3. Run entire collections with Collection Runner

Chapter 8: Data-Driven Testing with Collection Runner

1. Use a CSV or JSON file with variable data
2. Use {{variableName}} syntax in your request body
3. Open Collection Runner โ†’ Select data file โ†’ Run
Each iteration runs with a new row of data

Chapter 9: Pre-request Scripts

Used to set up data or headers before the request is sent.
Example:
pm.environment.set(“token”, “Bearer abc123”)

Chapter 10: Automation with Newman CLI

Newman is a command-line tool for running Postman collections.
Install with: npm install -g newman
Run with: newman run collection.json -e environment.json
Supports HTML report generation, CI/CD integration

Chapter 1: What is SOAP UI?

SOAP UI is a widely used tool for testing SOAP and REST web services. It allows testers and developers to create and execute automated functional, regression, compliance, and load tests on web APIs. SOAP UI supports data-driven testing, WSDL-based service testing, and has advanced capabilities like scripting and security testing.

Chapter 2: Installing SOAP UI

1. Go to https://www.soapui.org/downloads/soapui/
2. Choose the Open Source or ReadyAPI version
3. Download and install it for your operating system
4. Ensure Java Runtime Environment (JRE) is installed
5. Launch the SOAP UI tool

Chapter 3: Understanding WSDL

WSDL (Web Services Description Language) is an XML document that defines the structure of a SOAP service. It includes information about operations, inputs, outputs, and endpoints.
In SOAP UI, you use the WSDL URL to auto-generate all necessary request templates and project structure.

Chapter 4: Creating Your First SOAP Project

1. Open SOAP UI
2. File โ†’ New SOAP Project
3. Enter a name (e.g., CalculatorService)
4. Paste WSDL URL (e.g., http://www.dneonline.com/calculator.asmx?WSDL)
5. Click OK โ†’ SOAP UI generates requests under the service

Chapter 5: Sending Your First Request

1. Expand the service โ†’ operations (e.g., Add)
2. Double-click the request โ†’ fill values for <intA> and <intB>
3. Click the green arrow (Submit Request)
4. View the response from the service

Chapter 6: Assertions and Validations

Assertions validate the response from the service:
– XPath Match
– Contains/Not Contains
– Response SLA (performance)
– Script Assertion (Groovy based)
Add assertions by right-clicking the response and choosing ‘Add Assertion’

Chapter 7: Using Property Transfer

Property Transfer is used to pass data dynamically between requests.
Steps:
1. Add a Property Transfer step
2. Source: Response of one request โ†’ XPath value
3. Target: Input field of another request

Chapter 8: Groovy Scripting Basics

SOAP UI allows Groovy scripts for advanced control:
Example:
def token = context.expand(‘${Login#Response#//SessionID}’)
testRunner.testCase.setPropertyValue(‘sessionID’, token)

Chapter 9: Data-Driven Testing

1. Add a DataSource step (CSV or Excel)
2. Use property expansion: ${DataSource#columnName}
3. Loop with DataSource Loop step
4. Add assertion to validate each response

Chapter 10: WS-Security and Test Automation

SOAP UI supports WS-Security configurations:
– UsernameToken
– Timestamp
– Signature & Encryption (with keystore)

Tests can be executed from the command line using TestRunner:
testrunner.bat -sTestSuite -cTestCase path/to/project.xml

Chapter 1: What is REST Assured?

REST Assured is a Java-based library used to test RESTful APIs. It provides a domain-specific language (DSL) that simplifies validating and automating REST services. It is commonly used with Java frameworks like TestNG or JUnit.

Chapter 2: Setting Up REST Assured in a Maven Project

Steps:
1. Install Java and an IDE (e.g., IntelliJ, Eclipse)
2. Create a Maven project
3. Add dependency to pom.xml:
<dependency>
  <groupId>io.rest-assured</groupId>
  <artifactId>rest-assured</artifactId>
  <version>5.3.0</version>
</dependency>

Chapter 3: Writing Your First REST Assured Test

Example:
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
given().when().get(“https://jsonplaceholder.typicode.com/posts/1”).then().statusCode(200);

Chapter 4: Understanding the DSL Syntax

– `given()`: Setup like headers, parameters, body
– `when()`: Define the method (GET, POST, etc.)
– `then()`: Validate the response status, headers, and body

Chapter 5: GET and POST Requests

GET:
given().when().get(“/users/1”).then().statusCode(200);

POST:
given().header(“Content-Type”, “application/json”)
.body(“{\”name\”:\”Lok\”}”)
.when().post(“/users”).then().statusCode(201);

Chapter 6: Validating JSON Response

Example:
then().body(“name”, equalTo(“Lok”))
body(“email”, containsString(“@”))

Chapter 7: Query and Path Parameters

Query Param:
given().queryParam(“page”, 2).when().get(“/users”)

Path Param:
given().pathParam(“id”, 2).when().get(“/users/{id}”)

Chapter 8: Extracting Data from Response

Use extract() to store values:
String id = given().get(“/users/1”).then().extract().path(“id”);

Chapter 9: Logging Requests and Responses

Use log() for debugging:
log().all(), log().body(), log().headers()

Chapter 10: TestNG and CI Integration

– Integrate with TestNG for suite-level control
– Setup Jenkins or GitHub Actions to run `mvn test`
– Generate Allure or JUnit test reports from test runs

Scroll to Top