I have learned how to test web applications through the browser.
Next is API Testing.
I needed to know the server is returning the correct data, what happens when a request fails, and how to test login authentication without using the UI.
What is an API?
API stands for Application Programming Interface.
It allows different software applications or components to communicate with each other.
For example, when I search for a restaurant on QuickBite:
- The browser sends a request to the API.
- The API processes the request.
- The backend retrieves restaurant information.
- The API returns a response.
- The browser displays the results.
As a tester, I can test this communication directly without going through the user interface.
2. HTTP Methods
HTTP methods tell the server what action we want to perform.
The common methods include:
| Method | Purpose |
|---|---|
| GET | Retrieve data |
| POST | Create data |
| PUT | Replace a resource |
| PATCH | Partially update a resource |
| DELETE | Delete a resource |
For example:
GET /api/restaurants
POST /api/users
PATCH /api/users/1
DELETE /api/users/1
Understanding these methods helps to know what to expect from an API request.
3. HTTP Status Codes
After sending a request, the server returns a status code indicating the outcome.
Some common ones:
| Status | Meaning |
|---|---|
| 200 | OK |
| 201 | Created |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 500 | Internal Server Error |
For example:
If I submit valid registration details, I might expect:
201 Created
If I submit invalid data, I might expect:
400 Bad Request
The important thing is to verify that the response matches the API's requirements, not just that a status code is returned.
4. Request, Response, Headers & JSON
An API request contains information sent to the server.
An API response contains the information returned by the server.
A request can include:
- Method
- URL
- Headers
- Parameters
- Request body
Example registration request:
{
"name": "Joy",
"email": "joy@example.com",
"password": "Tester@101"
}
The server might respond with:
{
"id": 101,
"name": "Joy",
"email": "joy@example.com"
}
Headers also provide important information.
For example:
-
Content-Type: Describes the format of the request or response body. -
Accept: Indicates the response formats the client can accept. -
Authorization: Can carry authentication credentials.
As a tester, I need to verify both the response data and the relevant headers.
5. Testing APIs with Postman
One tool I am learning is Postman.
It allows me to send API requests and inspect responses without building a user interface.
For example, I tested:
GET https://jsonplaceholder.typicode.com/posts/1
I then inspect:
- Status code
- Response body
- Response headers
- Response time
I can also send POST, PUT, PATCH, and DELETE requests.
This makes it easier to test backend functionality independently of the frontend.
6. Writing API Test Cases
API testing also requires proper test design and documentation.
For example:
Test ID: TC_REG_001
Title: Register with valid information
Method: POST
Endpoint: /api/register
Test Data:
{
"name": "Joy",
"email": "joy@example.com",
"password": "Tester@101"
}
Expected Result:
- Response status should be 201 Created.
- A unique user ID should be returned.
- User information should be stored successfully.
- Password should not be exposed in the response.
Other scenarios to test:
- Registration with an existing email.
- Registration with missing fields.
- Registration with an invalid email.
- Login with incorrect credentials.
- Accessing protected endpoints without authentication.
The goal is to verify that the API behaves correctly under different conditions.
7. Authentication, Authorization & API Security
Not every API endpoint should be accessible to everyone.
Two important concepts:
Authentication: Verifies who you are.
Authorization: Determines what you're allowed to access.
For example:
A user logs in and receives an access token.
They use that token to access their order history.
As a tester, I should check:
- Access with a valid token.
- Access without a token.
- Access with an expired or invalid token.
- Whether one user can access another user's private data.
- Whether sensitive information, such as passwords, is exposed.
I also need to consider security issues such as SQL injection and improper input validation.
An API returning the correct response isn't enough. It must also protect the data and resources it handles.
What I am Learning
API testing has helped me understand that testing does not stop at the user interface alone.
A feature might look perfectly fine in the browser while the API behind it returns incorrect data, exposes sensitive information, or handles invalid requests improperly.
My approach is changing from:
"Does the feature work on the screen?"
To:
"Does the system communicate correctly, return the right data, handle errors, and protect its resources?"
That's another important part of becoming a better QA tester.
What's Next?
SQL and Database Testing.
Because sometimes, to understand whether an application is working correctly, I also need to understand what's happening to the data behind it.
Notes can be found here.
I'm learning QA and I'm taking you with me.
Top comments (0)