π Why API Testing Matters
API testing is a must-have skill for modern QA professionals. It helps you test the logic and functionality behind the user interface β often before the UI is even built.
Postman is one of the easiest tools to start with. Whether you’re a manual tester or learning automation, Postman helps you send requests, validate responses, and even write test scripts β all without needing to write full code.
π§ What Is Postman?
Postman is a free API client that lets you:
- Send requests to REST APIs
- Inspect responses (status, body, headers)
- Write basic tests using JavaScript
- Group requests into collections and environments
β Step-by-Step: Writing Your First API Test in Postman
Letβs go through an example using a public API:
π https://jsonplaceholder.typicode.com
Step 1: Set Up Postman
- Download Postman from postman.com
- Open the app and create a free account
Step 2: Make a Simple GET Request
Letβs get a list of fake posts from JSONPlaceholder:
URL:
arduinoCopyEdithttps://jsonplaceholder.typicode.com/posts
Method:GET
Click Send β youβll see a JSON response containing posts.
Step 3: Write a Test to Validate the Response
Scroll down to the Tests tab and paste this code:
javascriptCopyEditpm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response has at least one post", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.length).to.be.above(0);
});
π What this does:
- Asserts that the status code is
200
- Checks that the response contains at least one post
Step 4: Test a POST Request
Letβs send a POST request to create a new post.
URL:
arduinoCopyEdithttps://jsonplaceholder.typicode.com/posts
Method:POST
Body β raw β JSON:
jsonCopyEdit{
"title": "QA Playbook",
"body": "Learning API testing with Postman",
"userId": 1
}
Tests Tab:
javascriptCopyEditpm.test("Status code is 201", function () {
pm.response.to.have.status(201);
});
pm.test("Post contains correct title", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.title).to.eql("QA Playbook");
});
β This validates the response from a simulated post creation.
π§ͺ More Test Snippets for Beginners
β Check Response Time
javascriptCopyEditpm.test("Response time is less than 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});
β Check Content Type Header
javascriptCopyEditpm.test("Content-Type is application/json", function () {
pm.response.to.have.header("Content-Type");
});
β Validate a Property in the Response
javascriptCopyEditpm.test("User ID is 1", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.userId).to.eql(1);
});
π‘ Bonus Tips
- Use Environment Variables for dynamic data (e.g.,
{{base_url}}
) - Save your requests to Collections to reuse them
- Export your tests and share with your team
- Integrate with Newman CLI to run Postman tests from the command line
π Common Use Cases for Postman in QA
Use Case | Postman Feature |
---|---|
Validate API response format | Tests with pm.response.json() |
Check auth/login APIs | Use Authorization tab |
Automate test runs | Use Newman CLI + scripts |
Mock APIs for frontend devs | Postman’s Mock Server feature |
π― Final Thoughts
API testing doesnβt have to be overwhelming. Postman makes it simple to:
- Explore and understand how APIs work
- Validate backend logic without waiting for the UI
- Build confidence in testing more than just interfaces