Getting Started with Postman
Postman is the most popular tool for API testing, used by over 30 million developers and testers worldwide. It provides a visual interface for sending HTTP requests, inspecting responses, and writing automated test assertions — all without writing code.
Installation
Download Postman from postman.com/downloads. It’s available for Windows, macOS, and Linux. While there’s a web version, the desktop app offers better performance and additional features like local proxies and certificate management.
After installation, create a free account. While Postman can be used without an account, signing in enables cloud sync of your collections across devices.
The Postman Interface
The main workspace consists of:
- Sidebar — collections, environments, history
- Request builder — URL bar, method selector, tabs for params/headers/body/tests
- Response viewer — body, headers, status code, response time, size
- Console — logs from scripts and request details (View > Show Postman Console)
Your First Request
Let’s send a simple GET request:
- Click + to open a new request tab
- Select GET from the method dropdown
- Enter
https://jsonplaceholder.typicode.com/posts/1 - Click Send
You should see a JSON response with status 200 OK, containing userId, id, title, and body fields.
Now try a POST request:
- Change method to POST
- URL:
https://jsonplaceholder.typicode.com/posts - Go to Body tab > select raw > choose JSON
- Enter:
{
"title": "My First Post",
"body": "Testing with Postman",
"userId": 1
}
- Click Send — you should get 201 Created
Collections: Organizing Your Tests
Collections are folders that group related API requests. Think of them as test suites.
Creating a Collection
- Click Collections in the sidebar
- Click + to create a new collection
- Name it “JSONPlaceholder API Tests”
- Add folders for different resource types: Posts, Users, Comments
Adding Requests to Collections
Right-click your collection > Add Request. Name each request descriptively:
GET All PostsGET Single PostPOST Create PostPUT Update PostDELETE Remove Post
Collection Structure Best Practices
📁 Project API Tests
├── 📁 Authentication
│ ├── POST Login
│ ├── POST Register
│ └── POST Refresh Token
├── 📁 Users
│ ├── GET List Users
│ ├── GET Get User by ID
│ ├── POST Create User
│ ├── PUT Update User
│ └── DELETE Remove User
├── 📁 Orders
│ ├── GET List Orders
│ ├── POST Create Order
│ └── PATCH Update Order Status
└── 📁 Negative Tests
├── GET Non-existent Resource
├── POST Invalid Payload
└── DELETE Unauthorized
Variables and Environments
Variables eliminate hardcoded values and make your collections reusable across different environments (dev, staging, production).
Environment Variables
Create environments for each server:
Development:
base_url: http://localhost:3000/api
auth_token: dev-token-123
admin_email: admin@dev.example.com
Staging:
base_url: https://staging-api.example.com
auth_token: staging-token-456
admin_email: admin@staging.example.com
Use variables in requests with double curly braces:
GET {{base_url}}/users/{{user_id}}
Authorization: Bearer {{auth_token}}
Variable Scopes
Postman has four variable scopes (highest to lowest priority):
- Local — set in scripts, exist only during execution
- Environment — tied to the selected environment
- Collection — shared across all requests in a collection
- Global — available across all collections
Writing Tests in Postman
The Tests tab lets you write JavaScript assertions that run after receiving a response.
Basic Assertions
// Check status code
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// Check response time
pm.test("Response time is less than 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});
// Check response body contains expected data
pm.test("Response has correct user name", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.name).to.eql("Alice Johnson");
});
// Check response has required fields
pm.test("Response has all required fields", function () {
var jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("id");
pm.expect(jsonData).to.have.property("name");
pm.expect(jsonData).to.have.property("email");
});
// Check array length
pm.test("Returns at least 10 posts", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.length).to.be.at.least(10);
});
Chaining Requests with Variables
Extract values from responses and use them in subsequent requests:
// In POST Create User (Tests tab):
pm.test("Save created user ID", function () {
var jsonData = pm.response.json();
pm.environment.set("created_user_id", jsonData.id);
});
// In GET Get User (URL):
// {{base_url}}/users/{{created_user_id}}
Pre-Request Scripts
Run JavaScript before a request is sent:
// Generate a unique email for each test run
var timestamp = Date.now();
pm.environment.set("test_email", "user" + timestamp + "@test.com");
// Generate a random number
pm.environment.set("random_id", Math.floor(Math.random() * 1000));
Running Collections
Collection Runner
Click Run on a collection to execute all requests in sequence:
- Select environment
- Set iteration count (run the suite multiple times)
- Add data file (CSV/JSON) for data-driven testing
- Set delay between requests
- Click Run
The runner shows pass/fail for each test assertion and provides a summary.
Newman: Command-Line Runner
Newman runs Postman collections from the terminal, making it perfect for CI/CD.
Install Newman:
npm install -g newman
Run a collection:
# Export collection from Postman as JSON
newman run my-collection.json -e staging-environment.json
# With HTML report
newman run my-collection.json -e staging.json -r htmlextra
# Set number of iterations
newman run my-collection.json --iteration-count 5
CI/CD Integration Example (GitHub Actions)
- name: Run API Tests
run: |
npm install -g newman newman-reporter-htmlextra
newman run tests/api-collection.json \
-e tests/staging-env.json \
-r cli,htmlextra \
--reporter-htmlextra-export reports/api-report.html
Advanced Features
Data-Driven Testing
Create a CSV or JSON file with test data:
email,name,expected_status
valid@test.com,Alice,201
invalid-email,Bob,400
,Charlie,400
a@b.c,Dave,201
Reference data variables: {{email}}, {{name}}, {{expected_status}}
Mock Servers
Create mock APIs for frontend development or testing when the real API is unavailable. Postman generates a mock server URL based on your collection’s saved responses.
API Documentation
Postman auto-generates documentation from your collections, including request examples, response samples, and descriptions. Publish it as a public or private URL.
Hands-On Exercise
- Create a collection for JSONPlaceholder with requests for Posts CRUD operations
- Set up two environments (you can use the same URL with different variables to simulate)
- Write tests for each request checking status codes and response structure
- Chain requests: Create a post, extract its ID, fetch it by ID, update it, then delete it
- Run the collection using the Collection Runner and verify all tests pass
Key Takeaways
- Postman provides a visual interface for building, organizing, and running API tests without code
- Collections organize requests into logical groups; environments manage variables per server
- Variables (local, environment, collection, global) eliminate hardcoded values and enable reuse
- Test scripts use JavaScript assertions to validate status codes, response bodies, and headers
- Newman brings Postman collections to CI/CD pipelines for automated regression testing