0
0
Postmantesting~8 mins

First API request in Postman - Framework Patterns

Choose your learning style9 modes available
Framework Mode - First API request
Folder Structure
postman-api-project/
├── collections/
│   └── first-api-request.postman_collection.json
├── environments/
│   └── dev.postman_environment.json
├── tests/
│   └── first-api-request-tests.js
├── scripts/
│   └── pre-request-scripts.js
├── reports/
│   └── test-report.html
└── README.md
    
Test Framework Layers
  • Collections: Group of API requests organized logically (e.g., user APIs).
  • Environments: Store variables like base URLs, tokens for different setups (dev, prod).
  • Tests: Scripts written in JavaScript to validate API responses after requests run.
  • Pre-request Scripts: JavaScript code that runs before the API call to set up data or headers.
  • Reports: Generated test run reports showing pass/fail results and details.
Configuration Patterns

Use environment variables to manage different setups:

  • base_url: API base address (e.g., https://api.dev.example.com)
  • auth_token: Authorization token for secure APIs
  • Switch environments in Postman UI to run tests against dev, staging, or production

Store sensitive data securely and avoid hardcoding in requests or tests.

Test Reporting and CI/CD Integration
  • Use Newman (Postman CLI) to run collections in command line.
  • Generate HTML or JSON reports with Newman reporters.
  • Integrate Newman runs into CI/CD pipelines (e.g., GitHub Actions, Jenkins) to automate API testing on code changes.
  • Reports show which API requests passed or failed with details for debugging.
Best Practices
  1. Use environment variables for URLs and tokens to avoid hardcoding.
  2. Write clear test scripts that check status codes, response times, and data correctness.
  3. Organize collections logically by feature or API resource for easy maintenance.
  4. Use pre-request scripts to set dynamic data like timestamps or tokens.
  5. Integrate with CI/CD to catch API issues early and often.
Self Check

Where would you add a new API request for "User Login" in this framework structure?

Key Result
Organize API tests in Postman using collections, environments, scripts, and integrate with CI/CD for automated reporting.