# What is API testing?

> This section documents what is API Testing and why we need it

# 📘 What is API Testing?

**API Testing** is a type of software testing that focuses on verifying that **Application Programming Interfaces (APIs)** function as expected. Instead of testing the UI, API tests validate business logic, data responses, and the performance of an application’s backend services.

APIs act as the _bridge_ between different software systems — enabling communication and data exchange. Testing ensures these bridges are **reliable, secure, and performant**.

## ✅ Why Do We Need API Testing?

| Reason                            | Description                                                                                               |
| --------------------------------- | --------------------------------------------------------------------------------------------------------- |
| **1. Early Bug Detection**        | API testing is usually done before UI testing, allowing faster detection and resolution of critical bugs. |
| **2. Improved Test Coverage**     | Validates all layers of the application including edge cases, error codes, and data responses.            |
| **3. Faster Execution**           | API tests are faster than UI tests, enabling quicker feedback loops in CI/CD pipelines.                   |
| **4. Language-Agnostic**          | APIs can be tested independently of the frontend technology — enabling broader automation.                |
| **5. Enhanced Security**          | Validates authentication, authorization, and data privacy mechanisms.                                     |
| **6. Enables Continuous Testing** | Ideal for automated pipelines to ensure every build meets quality standards.                              |

## 🧪 What Do We Test in an API?

- Request & Response Validation
- Status Codes (200, 400, 500, etc.)
- Data Format (JSON, XML, etc.)
- Authentication & Authorization
- Load and Performance
- Edge Cases and Error Handling

## 🔍 Types of API Testing

| Type                                | Description                                                              |
| ----------------------------------- | ------------------------------------------------------------------------ |
| **Functional Testing**              | Ensures the API performs expected functions correctly with valid inputs. |
| **Validation Testing**              | Verifies the API meets business and technical requirements.              |
| **Load Testing**                    | Evaluates how the API handles a large volume of requests.                |
| **Security Testing**                | Checks for vulnerabilities, data leaks, and access control.              |
| **Error/Negative Testing**          | Validates behavior when given invalid inputs or unexpected conditions.   |
| **Regression Testing**              | Ensures recent changes haven't broken existing functionality.            |
| **Runtime and Reliability Testing** | Confirms the API's stability and availability during sustained use.      |

## ⚠️ Common Challenges in API Testing

- Lack of proper API documentation
- Handling dynamic responses and tokens
- Managing large test data and scenarios
- Testing across multiple environments (dev, staging, prod)
- Ensuring version compatibility and backward support
- Automating complex workflows involving chained API calls
