DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

LAB: DevOps API Testing with Postman (FULL REAL SCENARIO)

🎯 Goal

You are a DevOps engineer validating an API before deployment.

You will:

  1. Discover API
  2. Test manually
  3. Validate response
  4. Add automation tests
  5. Run in CLI (Newman)
  6. Integrate into CI/CD mindset

🧠 PART 1 β€” What is API (DevOps perspective)

πŸ‘‰ API = endpoint where services communicate

Example:

Frontend β†’ API β†’ Backend β†’ Database
Enter fullscreen mode Exit fullscreen mode

Real example:

https://jsonplaceholder.typicode.com/users
Enter fullscreen mode Exit fullscreen mode
  • https:// β†’ protocol
  • jsonplaceholder.typicode.com β†’ API server
  • /users β†’ endpoint

🧠 PART 2 β€” Where DevOps finds API

DevOps gets API from:

  • Developers (Swagger / OpenAPI)
  • GitHub repo (README)
  • Environment variables
  • Load balancer (ALB DNS)
  • Kubernetes Ingress
  • API Gateway (AWS)

πŸ‘‰ Example in AWS:

http://my-alb-123.us-east-1.elb.amazonaws.com/users
Enter fullscreen mode Exit fullscreen mode

🧠 PART 3 β€” What DevOps tests (IMPORTANT)

DevOps DOES NOT test UI
DevOps tests:

βœ… 1. Availability

  • API reachable?
  • Status = 200?

βœ… 2. Correct response

  • JSON format correct?
  • Required fields exist?

βœ… 3. Performance (basic)

  • Response time < 500ms?

βœ… 4. Security basics

  • Unauthorized access blocked?

βœ… 5. Integration

  • Does backend connect to DB?

πŸš€ PART 4 β€” HANDS-ON LAB


πŸ“ Step 1 β€” Create Postman Collection

  1. Open Postman
  2. Click New β†’ Collection
  3. Name: devops-api-lab

πŸ“ Step 2 β€” Create Environment

Environment:

base_url = https://jsonplaceholder.typicode.com
Enter fullscreen mode Exit fullscreen mode

πŸ“ Step 3 β€” CREATE REQUESTS


βœ… TEST 1 β€” GET USERS (Availability Test)

Request:

GET {{base_url}}/users
Enter fullscreen mode Exit fullscreen mode

Tests tab (IMPORTANT):

pm.test("Status is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Response is JSON", function () {
    pm.response.to.be.json;
});

pm.test("Response time < 500ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(500);
});
Enter fullscreen mode Exit fullscreen mode

βœ… TEST 2 β€” VALIDATE DATA STRUCTURE

pm.test("User has required fields", function () {
    const jsonData = pm.response.json();

    pm.expect(jsonData[0]).to.have.property("id");
    pm.expect(jsonData[0]).to.have.property("name");
    pm.expect(jsonData[0]).to.have.property("email");
});
Enter fullscreen mode Exit fullscreen mode

βœ… TEST 3 β€” CREATE USER (POST)

Request:

POST {{base_url}}/users
Enter fullscreen mode Exit fullscreen mode

Body (JSON):

{
  "name": "DevOps Engineer",
  "job": "Cloud Engineer"
}
Enter fullscreen mode Exit fullscreen mode

Tests:

pm.test("Created successfully", function () {
    pm.response.to.have.status(201);
});
Enter fullscreen mode Exit fullscreen mode

βœ… TEST 4 β€” NEGATIVE TEST (DevOps important)

Request:

GET {{base_url}}/invalid-endpoint
Enter fullscreen mode Exit fullscreen mode

Tests:

pm.test("Should return 404", function () {
    pm.response.to.have.status(404);
});
Enter fullscreen mode Exit fullscreen mode

🧠 PART 5 β€” HOW DEVOPS THINKS

DevOps checks:

Check Why
200 OK Service is alive
JSON valid Backend works
Fields exist Contract not broken
Response time Performance
404/401 Security + routing

πŸš€ PART 6 β€” AUTOMATION (VERY IMPORTANT)

Export your collection:

collection.json
environment.json
Enter fullscreen mode Exit fullscreen mode

Run with Newman:

npm install -g newman
Enter fullscreen mode Exit fullscreen mode

Run:

newman run collection.json -e environment.json
Enter fullscreen mode Exit fullscreen mode

🚨 REAL DEVOPS SCENARIO

Pipeline step:

- name: Run API Tests
  run: newman run collection.json -e environment.json
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ If tests fail β†’ deployment FAILS


🧠 PART 7 β€” HOW TO KNOW WHAT OUTPUT SHOULD BE

DevOps gets expected output from:

  1. Swagger (OpenAPI)
  2. Developer documentation
  3. Existing production API
  4. Contract testing

Example expected:

{
  "id": 1,
  "name": "Leanne Graham"
}
Enter fullscreen mode Exit fullscreen mode

🧠 PART 8 β€” HOW TO FIND API IN REAL SYSTEM

In Kubernetes:

kubectl get svc
kubectl get ingress
Enter fullscreen mode Exit fullscreen mode

In AWS:

  • ALB DNS
  • API Gateway URL

In Docker:

docker logs container
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ FINAL UNDERSTANDING

DevOps API Testing Level:

  • NOT deep functional testing (QA job)
  • YES:

    • Health checks
    • Contract validation
    • Automation in pipeline
    • Basic security & performance

πŸ’‘ BONUS (REAL INTERVIEW ANSWER)

πŸ‘‰ If interviewer asks:

"What do DevOps test with Postman?"

Answer:

DevOps engineers use Postman to validate API availability, response correctness, status codes, and response time. We also automate these tests using Newman in CI/CD pipelines to ensure deployments don’t break existing functionality.

Top comments (0)