Bird
Raised Fist0
Postmantesting~8 mins

Why HTTP methods define API intent in Postman - Framework Benefits

Choose your learning style10 modes available
Framework Mode - Why HTTP methods define API intent
Folder Structure of a Postman API Test Project
Postman-API-Tests/
├── collections/
│   ├── user-management.postman_collection.json
│   ├── product-catalog.postman_collection.json
│   └── order-processing.postman_collection.json
├── environments/
│   ├── dev.postman_environment.json
│   ├── staging.postman_environment.json
│   └── prod.postman_environment.json
├── scripts/
│   ├── pre-request-scripts.js
│   └── test-scripts.js
├── reports/
│   └── test-run-report.html
├── README.md
└── postman.config.json
Test Framework Layers in Postman API Testing
  • Collections: Group of API requests organized by feature or service, each request uses HTTP methods to define intent (GET, POST, PUT, DELETE, PATCH).
  • Environments: Variables for different deployment stages (dev, staging, prod) to run tests against different API endpoints.
  • Scripts: Pre-request scripts to set up data or headers, and test scripts to validate responses and assert API behavior.
  • Reports: Generated test run reports showing pass/fail status of API tests.
  • Configuration: Settings for running collections, environment selection, and global variables.
Configuration Patterns for Postman API Testing
  • Environment Variables: Define base URLs, authentication tokens, and other dynamic data per environment to avoid hardcoding.
  • Collection Variables: Store reusable values like common headers or IDs within a collection scope.
  • Global Variables: Use sparingly for values shared across collections.
  • Authentication Setup: Use pre-request scripts to dynamically generate or refresh tokens.
  • HTTP Method Usage: Clearly define API intent by using correct HTTP methods: GET for reading data, POST for creating, PUT for full updates, PATCH for partial updates, and DELETE for removals.
Test Reporting and CI/CD Integration
  • Newman CLI: Run Postman collections from command line to integrate with CI/CD pipelines.
  • HTML Reports: Generate readable reports after test runs showing which HTTP methods passed or failed.
  • CI/CD Tools: Integrate with Jenkins, GitHub Actions, GitLab CI to automate API tests on code changes.
  • Alerts: Configure notifications on test failures to quickly identify API issues related to HTTP method misuse.
Best Practices for Defining API Intent with HTTP Methods
  1. Use HTTP Methods Correctly: Always match the method to the action: GET to retrieve, POST to create, PUT/PATCH to update, DELETE to remove.
  2. Clear Naming in Collections: Name requests to reflect the HTTP method and action, e.g., "POST Create User".
  3. Validate Status Codes: Assert expected HTTP status codes (200, 201, 204, 400, 404) to confirm correct API behavior.
  4. Use Environment Variables: Avoid hardcoding URLs or tokens to keep tests flexible across environments.
  5. Document Intent: Add descriptions in Postman requests explaining the purpose of each HTTP method used.
Self Check Question

In the folder structure shown, where would you add a new POST request to create a new product in the API?

Key Result
Use HTTP methods in Postman collections to clearly define and test API intent.

Practice

(1/5)
1. Which HTTP method is typically used to retrieve data from an API without changing any data?
easy
A. PUT
B. GET
C. DELETE
D. POST

Solution

  1. Step 1: Understand the purpose of HTTP methods

    GET is used to request data without modifying it, making it safe and idempotent.
  2. Step 2: Match method to action

    Since the question asks for retrieving data without changes, GET fits perfectly.
  3. Final Answer:

    GET -> Option B
  4. Quick Check:

    Retrieve data = GET [OK]
Hint: GET is for reading data only, no changes [OK]
Common Mistakes:
  • Confusing POST with GET for data retrieval
  • Thinking DELETE retrieves data
  • Using PUT instead of GET for reading
2. Which of the following is the correct syntax to send data to create a new resource using Postman?
easy
A. Use GET method with a request body
B. Use PUT method without a request body
C. Use DELETE method with a request body
D. Use POST method with a request body

Solution

  1. Step 1: Identify method for creating resources

    POST is the standard HTTP method to create new resources and it requires a request body with data.
  2. Step 2: Check syntax correctness

    GET should not have a body, DELETE is for removing, and PUT usually updates or replaces resources with a body.
  3. Final Answer:

    Use POST method with a request body -> Option D
  4. Quick Check:

    Create resource = POST + body [OK]
Hint: POST creates with data in body, GET never has body [OK]
Common Mistakes:
  • Trying to send body with GET method
  • Using DELETE to create data
  • Assuming PUT never needs a body
3. Consider this Postman request using PUT method to update a user profile. What is the expected behavior?
medium
A. It replaces the entire user profile with the provided data.
B. It partially updates the user profile fields.
C. It creates a new user if the user ID does not exist.
D. It deletes the user profile.

Solution

  1. Step 1: Understand the PUT method intent

    PUT is used to replace the entire resource at the given URL with the data sent in the request.
  2. Step 2: Differentiate from PATCH and DELETE

    PATCH partially updates, DELETE removes, and PUT replaces fully or creates if missing.
  3. Final Answer:

    It replaces the entire user profile with the provided data. -> Option A
  4. Quick Check:

    PUT = full replace [OK]
Hint: PUT replaces whole resource, PATCH updates parts [OK]
Common Mistakes:
  • Confusing PUT with PATCH for partial updates
  • Thinking PUT deletes data
  • Assuming PUT never creates new resource
4. You sent a PATCH request in Postman to update a user's email, but the entire user data was overwritten instead. What is the likely cause?
medium
A. The server treats PATCH like PUT and replaces the whole resource.
B. PATCH requests cannot update email fields.
C. You used GET method instead of PATCH.
D. The request body was empty.

Solution

  1. Step 1: Understand PATCH vs PUT behavior

    PATCH is meant for partial updates, but some servers treat PATCH like PUT and replace the entire resource.
  2. Step 2: Analyze the problem

    Since the entire data was overwritten, the server likely did not handle PATCH correctly and replaced the resource.
  3. Final Answer:

    The server treats PATCH like PUT and replaces the whole resource. -> Option A
  4. Quick Check:

    Server misinterprets PATCH as PUT [OK]
Hint: Server may treat PATCH as full replace (PUT) [OK]
Common Mistakes:
  • Assuming PATCH cannot update specific fields
  • Confusing PATCH with GET method
  • Ignoring empty request body possibility
5. You want to design an API endpoint in Postman that safely deletes a user but only if the user exists. Which HTTP method and response status code combination best defines this intent?
hard
A. Use GET method and return 204 No Content
B. Use POST method and return 200 OK always
C. Use DELETE method and return 404 Not Found if user missing
D. Use PUT method and return 201 Created

Solution

  1. Step 1: Choose correct HTTP method for deletion

    DELETE is the standard method to remove resources safely.
  2. Step 2: Select appropriate response code for missing resource

    If the user does not exist, returning 404 Not Found clearly informs the client.
  3. Final Answer:

    Use DELETE method and return 404 Not Found if user missing -> Option C
  4. Quick Check:

    Delete + 404 if missing = safe API [OK]
Hint: DELETE removes; 404 means resource not found [OK]
Common Mistakes:
  • Using POST to delete resources
  • Returning 200 OK even if user missing
  • Using GET or PUT incorrectly for deletion
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard