API Testing Fundamentals for E2E Testers
Why API-level tests are the fastest layer of your pyramid, and how to start writing them alongside UI tests.
July 29, 20266 min read

API Testing Fundamentals for E2E Testers: A Practical Guide
Introduction
Many End-to-End (E2E) testers begin their automation journey by interacting with the application's user interface. Tools like Playwright, Cypress, and Selenium make it easy to automate user workflows by clicking buttons, filling forms, and verifying page content.
However, relying solely on UI automation has its drawbacks:
- Tests are slower.
- UI changes frequently.
- Locating the root cause of failures becomes difficult.
- Setting up test data through the UI is inefficient.
This is where API Testing becomes an essential skill. Understanding how APIs work allows E2E testers to build faster, more reliable, and easier-to-maintain automation suites.
In this article, we'll cover the fundamentals of API testing from an E2E tester's perspective, along with practical examples using Playwright.
What is an API?
API stands for Application Programming Interface.
Think of an API as a waiter in a restaurant.
Customer
↓
Waiter (API)
↓
Kitchen (Backend)
↓
Waiter (API)
↓
Customer
The customer doesn't cook the food.
The customer simply sends a request, and the waiter delivers the response.
Similarly:
- Your frontend sends a request.
- The backend processes it.
- The API returns a response.
Why Should E2E Testers Learn API Testing?
Many UI actions trigger API calls behind the scenes.
For example:
Click Login Button
↓
POST /login
↓
Authentication Service
↓
Access Token
↓
Dashboard
If the login page fails, how do you know whether the issue is:
- UI bug?
- Backend bug?
- Authentication service?
- Network issue?
API testing helps answer these questions much faster.
Benefits of API Testing
Compared with UI testing, API tests are:
- Faster
- More stable
- Easier to debug
- Independent of UI changes
- Ideal for creating test data
- Perfect for validating business logic
Instead of navigating through multiple pages just to create a user, you can simply call an API.
HTTP Methods Every Tester Should Know
Most REST APIs use four common HTTP methods.
| Method | Purpose |
|---|---|
| GET | Retrieve data |
| POST | Create new data |
| PUT | Replace existing data |
| PATCH | Update part of existing data |
| DELETE | Remove data |
Example:
GET /users
POST /users
PUT /users/10
PATCH /users/10
DELETE /users/10
Anatomy of an API Request
Every API request consists of several parts.
POST https://api.example.com/users
Headers
Authorization: Bearer Token
Body
{
"name": "John",
"email": "john@test.com"
}
Components include:
- URL
- HTTP Method
- Headers
- Query Parameters
- Request Body
- Authentication
Understanding HTTP Status Codes
Status codes indicate whether a request succeeds or fails.
| Status Code | Meaning |
|---|---|
| 200 | OK |
| 201 | Created |
| 204 | No Content |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 409 | Conflict |
| 422 | Validation Error |
| 500 | Internal Server Error |
Example:
POST /users
↓
201 Created
or
POST /users
↓
400 Bad Request
JSON: The Language of APIs
Most modern APIs exchange data using JSON.
Example response:
{
"id": 101,
"name": "Alice",
"email": "alice@test.com",
"role": "Admin"
}
E2E testers should know how to verify:
- Data types
- Required fields
- Nested objects
- Arrays
- Null values
Authentication Basics
Most APIs require authentication.
Common authentication methods include:
- Bearer Token
- OAuth 2.0
- API Key
- Basic Authentication
- JWT
Example:
Authorization: Bearer eyJhbGc...
Without valid credentials:
401 Unauthorized
Common API Test Scenarios
A good API test doesn't just verify the happy path.
Examples include:
Positive Tests
- Create a user successfully
- Login successfully
- Retrieve user profile
- Update user information
- Delete a user
Negative Tests
- Missing required fields
- Invalid password
- Expired token
- Invalid email format
- Duplicate username
API Testing with Playwright
Playwright provides a built-in API testing library.
Example:
import { test, expect } from '@playwright/test';
test('Get user profile', async ({ request }) => {
const response = await request.get('/api/users/1');
expect(response.status()).toBe(200);
const body = await response.json();
expect(body.id).toBe(1);
expect(body.name).toBeTruthy();
});
No browser is launched.
The test communicates directly with the backend.
Creating Test Data via API
Instead of:
Open Browser
↓
Login
↓
Navigate
↓
Fill Form
↓
Submit
↓
Verify
You can simply:
POST /users
↓
Receive User ID
↓
Run UI Test
This dramatically reduces test execution time.
Combining API and UI Testing
One of the most powerful automation strategies is combining both.
Example workflow:
Create User (API)
↓
Login (API)
↓
Open Dashboard (UI)
↓
Verify User Information (UI)
↓
Delete User (API)
This approach:
- Speeds up execution
- Makes tests independent
- Simplifies cleanup
- Reduces flaky tests
Validating API Responses
Don't only verify status codes.
Also validate:
- Response body
- Data types
- Required fields
- Business rules
- Response time
Example:
expect(response.status()).toBe(200);
expect(body.email).toContain('@');
expect(body.role).toBe('Admin');
Performance Considerations
Even simple API tests can monitor response times.
Example:
const start = Date.now();
const response = await request.get('/products');
const duration = Date.now() - start;
expect(duration).toBeLessThan(1000);
Slow APIs often indicate performance issues before users notice them.
Best Practices
1. Test APIs Independently
Avoid relying on the UI to prepare data whenever possible.
2. Verify More Than Status Codes
Always validate response content, business rules, and data integrity.
3. Use Independent Test Data
Generate unique users, emails, or IDs to avoid conflicts between test runs.
4. Keep Authentication Reusable
Store authentication logic in helper functions or fixtures rather than duplicating code.
5. Clean Up Test Data
Delete any created records after tests complete to keep environments clean.
6. Separate API Utilities
Organize API requests into reusable service classes.
Example:
api/
├── AuthAPI.ts
├── UserAPI.ts
├── ProductAPI.ts
└── OrderAPI.ts
7. Combine API and UI Wisely
Use APIs for setup and cleanup.
Reserve UI automation for validating user interactions and visual behaviour.
Real-World Example
Imagine testing an e-commerce checkout flow.
Traditional UI-only approach:
Register User (UI)
↓
Verify Email
↓
Login
↓
Add Product
↓
Checkout
↓
Logout
Optimized approach:
Create User (API)
↓
Generate Authentication Token (API)
↓
Open Checkout Page (UI)
↓
Complete Payment (UI)
↓
Verify Order (API)
↓
Delete User (API)
The second approach is significantly faster, more reliable, and easier to maintain.
Conclusion
API testing is no longer optional for modern E2E testers—it's a core skill. By understanding HTTP methods, authentication, JSON, status codes, and API validation techniques, testers can build automation frameworks that are faster, more stable, and easier to debug.
When combined with tools like Playwright, API testing becomes a powerful companion to UI automation. Use APIs to prepare data, validate backend behaviour, and clean up test environments, while keeping UI tests focused on the actual user experience.
Mastering API fundamentals will not only improve the quality of your automation suite but also make you a more versatile and valuable QA engineer.