Postman

Development Tool

Postman

Overview

Postman is the industry-standard tool for API development. It provides a comprehensive API development environment including testing, mock creation, documentation generation, and team collaboration.

Details

Postman began as a Chrome extension developed by Siddhartha Puri in 2012 and has now evolved into the world's most widely used API development platform. What started as simple HTTP request functionality has evolved into a comprehensive platform supporting the entire enterprise-level API development lifecycle. The intuitive GUI enables API endpoint creation, testing, and documentation, while complex workflows can be managed visually. Collection features allow grouping of API requests, and environment variables streamline configuration management across different development stages. The mock functionality enables development before API implementation, while automated testing features enable continuous quality assurance. Team features enable multi-person collaboration, providing integrated management from API design through testing to deployment.

Advantages and Disadvantages

Advantages

  • Intuitive Interface: GUI design accessible even to non-technical users
  • Comprehensive Features: Centralized testing, mocking, documentation, and monitoring
  • Team Collaboration: Collection sharing and real-time collaboration
  • Rich Authentication Support: Wide support for OAuth, JWT, Basic Auth, etc.
  • Environment Management: Easy switching between development, test, and production environments
  • Automated Testing: Test automation through CI/CD pipeline integration
  • Rich Ecosystem: Extensibility through plugins and APIs

Disadvantages

  • Paid Plans: Advanced features and team usage require subscription
  • Data Privacy: Concerns about data storage in the cloud
  • Learning Curve: Time required to utilize advanced features
  • Performance: Can be slow when processing large volumes of requests
  • Offline Limitations: Some features require internet connection

Key Links

Usage Examples

Basic GET Request

// Environment variable setup example
{
  "baseUrl": "https://api.example.com",
  "apiKey": "{{API_KEY}}"
}

// GET request URL example
{{baseUrl}}/users/{{userId}}?api_key={{apiKey}}

// Headers configuration
Content-Type: application/json
Authorization: Bearer {{token}}

POST Request with Data

// Body (raw JSON)
{
  "name": "John Doe",
  "email": "[email protected]",
  "age": 30,
  "department": "engineering"
}

// Pre-request Script example
pm.environment.set("timestamp", Date.now());
pm.environment.set("uuid", pm.variables.replaceIn('{{$guid}}'));

Response Testing

// Assertion examples in Tests tab
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Response time is less than 1000ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(1000);
});

pm.test("User created successfully", function () {
    const responseJson = pm.response.json();
    pm.expect(responseJson.status).to.eql("success");
    pm.expect(responseJson.data.id).to.exist;
    
    // Save to variable for next request
    pm.environment.set("userId", responseJson.data.id);
});

pm.test("Required fields exist", function () {
    const responseJson = pm.response.json();
    pm.expect(responseJson.data).to.have.property("name");
    pm.expect(responseJson.data).to.have.property("email");
    pm.expect(responseJson.data.email).to.include("@");
});

Authentication Setup

// OAuth 2.0 configuration example
// Set in Authorization tab
Grant Type: Authorization Code
Auth URL: https://auth.example.com/oauth/authorize
Access Token URL: https://auth.example.com/oauth/token
Client ID: {{clientId}}
Client Secret: {{clientSecret}}
Scope: read write

// JWT token preprocessing
// Pre-request Script
const credentials = {
    username: pm.environment.get("username"),
    password: pm.environment.get("password")
};

pm.sendRequest({
    url: pm.environment.get("authUrl") + "/login",
    method: 'POST',
    header: {
        'Content-Type': 'application/json'
    },
    body: {
        mode: 'raw',
        raw: JSON.stringify(credentials)
    }
}, function (err, response) {
    if (err) {
        console.error(err);
    } else {
        const token = response.json().token;
        pm.environment.set("jwtToken", token);
    }
});

Dynamic Data Generation

// Dynamic variables usage example
{
  "id": "{{$guid}}",
  "timestamp": "{{$timestamp}}",
  "randomString": "{{$randomString}}",
  "randomEmail": "{{$randomEmail}}",
  "randomFirstName": "{{$randomFirstName}}",
  "randomLastName": "{{$randomLastName}}",
  "randomInt": "{{$randomInt}}"
}

// Custom dynamic data generation (Pre-request Script)
const faker = require('faker');

pm.environment.set("randomName", faker.name.findName());
pm.environment.set("randomCompany", faker.company.companyName());
pm.environment.set("randomAddress", faker.address.streetAddress());

Collection Automation

# Automation example using Newman (CLI Postman)
npm install -g newman

# Running collection
newman run "API Collection.postman_collection.json" \
  --environment "Production.postman_environment.json" \
  --reporters cli,json \
  --reporter-json-export results.json

# CI/CD pipeline usage example (GitHub Actions)
name: API Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install Newman
        run: npm install -g newman
      - name: Run API Tests
        run: newman run postman/collection.json -e postman/env.json