Testing REST APIs with Postman is one of the easiest and most powerful ways to validate API endpoints, automate tests, and debug issues. Below is a complete, beginner-friendly, and practical guide for using Postman to test REST APIs.
๐ What Is Postman?
Postman is a popular tool for:
Sending HTTP requests to APIs
Inspecting responses
Writing automated tests
Creating documentation
Running test collections in CI/CD
Mocking APIs
Perfect for testing Spring Boot, .NET, Node.js, Python, or any REST API.
๐งฉ 1. Installing Postman
Download from: https://www.postman.com/downloads
Postman works on Windows, macOS, and Linux.
๐ 2. Making Your First Request
Example: Send a GET request
Open Postman
Click New → Request
Choose method: GET
Enter URL (example):
http://localhost:8080/api/users
Click Send
You will see:
Status Code (200 OK, 404, 500...)
Response Body (JSON, XML, HTML)
Headers
Time & size
๐งช 3. Testing Different HTTP Methods
✔ GET
Retrieve data.
GET http://localhost:8080/api/users
✔ POST
Create new resources.
Example JSON body:
{
"name": "Alice",
"email": "alice@example.com"
}
Steps in Postman:
Select POST
Go to Body
Choose raw
Select type JSON
Paste JSON
Click Send
✔ PUT / PATCH
Update resources.
PUT http://localhost:8080/api/users/5
✔ DELETE
Delete a resource.
DELETE http://localhost:8080/api/users/5
๐ 4. Sending Authentication
✔ Basic Auth
Go to Authorization → Basic Auth
Enter username/password.
✔ Bearer Token (JWT)
Go to Authorization → Bearer Token
Paste the token.
Example JWT:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
✔ API Keys
Use Header or Query Params:
x-api-key: <your-key>
๐งต 5. Sending Headers
Example:
Content-Type: application/json
Accept: application/json
Authorization: Bearer <token>
In Postman:
Go to Headers
Add key-value pairs
๐ฆ 6. Sending Query Parameters
Example URL:
GET http://localhost:8080/api/users?page=1&size=10
In Postman:
Go to Params
Add key/value
page = 1
size = 10
Postman automatically appends them to your URL.
๐งช 7. Writing Tests in Postman (Automated Tests)
Postman supports JavaScript tests using the Tests tab.
Example: Basic test
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
Example: Validate JSON field
pm.test("Name is correct", function () {
const data = pm.response.json();
pm.expect(data.name).to.eql("Alice");
});
Example: Check response time
pm.test("Response time < 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});
Example: Validate array size
pm.test("Users count > 0", function () {
pm.expect(pm.response.json().length).to.be.greaterThan(0);
});
๐ 8. Using Collections
Collections let you group requests—useful for API suites.
Create a collection:
Click New → Collection
Add requests
Add tests, environment variables, authentication rules
Benefits:
Organization
Reusability
Sharing
CI/CD automation
๐ 9. Environment Variables
Use variables to avoid hardcoding URLs, tokens, etc.
Example variables:
{{base_url}} → http://localhost:8080
{{token}} → JWT token
Create environment:
Click Environments
Add variables
Use in requests:
{{base_url}}/api/users
Set token automatically from login request:
Tests tab of login request:
pm.environment.set("token", pm.response.json().token);
๐♂️ 10. Running Collections Automatically (Collection Runner)
Go to:
Runner → Select Collection → Run
You can configure:
Iterations
Data files (CSV/JSON)
Environments
Great for regression testing.
๐ 11. Running Tests in CI/CD (Newman)
Install Newman (Postman CLI):
npm install -g newman
Run collection:
newman run MyCollection.json -e dev_environment.json
Integrate in:
GitHub Actions
Jenkins
Azure DevOps
GitLab CI
๐งช Summary Table
Feature Purpose
GET/POST/PUT/DELETE tests Verify API functionality
Headers & Params Customize request metadata
Auth (Basic/JWT/API Key) Secure API access
Tests (JS assertions) Automate validation
Collections Organize and group requests
Environments Reuse variables like base URL, token
Runner Execute automated API test suites
Newman Run tests in pipelines
Learn Full Stack JAVA Course in Hyderabad
Read More
Integrating Thymeleaf with Spring Boot
Exception Handling in Spring Boot
Spring Boot Annotations You Must Know
Dependency Injection in Spring Framework
Visit Our Quality Thought Institute in Hyderabad
Subscribe by Email
Follow Updates Articles from This Blog via Email
No Comments