DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

API #2

1. What happens FIRST (Developer side)

Developer creates API

Example:

  • Endpoint: POST /orders
  • Logic: create order in DB
  • Returns: JSON response

They define:

  • Request format
  • Response format
  • Status codes

Often documented using:

  • Swagger / OpenAPI

2. WHO validates APIs (very important)

Role What they validate
Developer Basic functionality (unit tests)
QA Engineer Functional testing
DevOps Engineer System + deployment + integration validation

πŸ‘‰ DevOps is NOT replacing QA
πŸ‘‰ DevOps ensures API works in real infrastructure


3. WHEN DevOps validates APIs

Timeline:

  1. Developer writes API
  2. Code pushed to Git
  3. CI/CD pipeline starts
  4. App deployed (Dev / Stage)
  5. DevOps validates APIs here
  6. Then production release

πŸ‘‰ DevOps validation happens:

  • After deployment
  • During pipeline
  • After infra changes
  • During incidents

4. WHERE DevOps tests APIs

Environment Purpose
Dev Early testing
Stage Pre-production validation
Prod Monitoring / smoke tests

πŸ‘‰ DevOps ALWAYS tests across environments using variables


5. WHAT DevOps validates (THIS IS THE CORE)

1. API Availability

GET /health
Enter fullscreen mode Exit fullscreen mode

Check:

  • API is reachable
  • No downtime

2. Status Codes

200 β†’ success  
400 β†’ bad request  
401 β†’ unauthorized  
500 β†’ server error
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ DevOps ensures:

  • No unexpected 500 errors after deployment

3. Response Structure

Example:

{
  "id": 123,
  "status": "created"
}
Enter fullscreen mode Exit fullscreen mode

Check:

  • Required fields exist
  • No breaking changes

4. Authentication

Example:

Authorization: Bearer token
Enter fullscreen mode Exit fullscreen mode

Check:

  • Token works
  • Expired token fails
  • Permissions enforced

5. Integration Between Services

Example:

  • API β†’ Database
  • API β†’ Kafka
  • API β†’ another microservice

πŸ‘‰ DevOps checks:

  • Full flow works (not just API)

6. Performance / Latency

Check:

  • Response time < expected (e.g., 200ms)

7. Error Handling

Send bad request:

{
  "wrong": "data"
}
Enter fullscreen mode Exit fullscreen mode

Check:

  • Proper error message
  • No crash

8. Idempotency / Stability

Run same request multiple times:

  • Does it duplicate?
  • Does it break?

6. HOW DevOps validates APIs (TOOLS + FLOW)

Step 1: Use Postman for manual + automation

  • Create collections
  • Add tests
  • Use environments

Step 2: Automate using Newman

Run in pipeline:

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

Step 3: Add into CI/CD

Example flow:

  1. Code pushed
  2. Build Docker image
  3. Deploy to ECS / Kubernetes
  4. Run API tests (Postman/Newman)
  5. If failed β†’ stop pipeline

Step 4: Monitoring (after deployment)

Tools:

  • CloudWatch
  • Prometheus
  • API Gateway logs

Check:

  • API errors
  • Latency
  • Traffic

7. REAL DEVOPS FLOW (END-TO-END)

Step-by-step:

1. Developer

  • Writes API
  • Pushes code

2. CI Pipeline

  • Build app
  • Run unit tests

3. CD Pipeline

  • Deploy to Dev/Stage (ECS / EKS / VM)

4. DevOps Validation (THIS IS YOU)

You run:

A. Smoke test

  • API is up

B. Functional test

  • GET / POST works

C. Integration test

  • DB / Kafka works

D. Security test

  • Auth works

5. Automated Gate

If tests fail:

  • ❌ STOP deployment

If pass:

  • βœ… Continue to production

6. Production Monitoring

  • Alerts if API fails
  • Auto rollback possible

8. REAL EXAMPLE Kafka project

deployed backend API:

POST /orders
GET /orders
Enter fullscreen mode Exit fullscreen mode

DevOps checks:

  1. API reachable via ALB
  2. Kafka receives message
  3. Consumer processes data
  4. Data stored in DB
  5. API returns correct response

πŸ‘‰ This is end-to-end validation


9. COMMON INTERVIEW QUESTION (VERY IMPORTANT)

Question:

β€œWhat does DevOps validate in APIs?”

Answer:

β€œDevOps engineers validate APIs after deployment by checking availability, status codes, authentication, response structure, and integration with downstream services. We automate these validations using tools like Postman/Newman in CI/CD pipelines to ensure reliable deployments.”


10. BIG PICTURE (REMEMBER THIS)

DevOps is responsible for:

  • Not just β€œAPI works”
  • But:

    • Works after deployment
    • Works with infrastructure
    • Works under load
    • Works securely
    • Works continuously

What is Newman?

Newman is the command-line tool for Postman collections.

πŸ‘‰ In simple words:

Postman = GUI (manual + design)
Newman = CLI (automation + pipelines)


Simple analogy

  • Postman β†’ like clicking buttons in browser
  • Newman β†’ like running script in terminal (automation)

When do we use Postman?

Use Postman when:

  • You are developing APIs
  • You are testing manually
  • You are learning/debugging
  • You are creating collections

Example:

  • Try GET /users
  • Check response
  • Write test scripts
  • Save collection

πŸ‘‰ This is interactive work


When do we use Newman?

Use Newman when:

  • Running tests automatically
  • In CI/CD pipelines
  • After deployment
  • For regression testing

Example:

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

πŸ‘‰ This is automation (no clicking)


Real DevOps Workflow (IMPORTANT)

Step 1 β€” In Postman (Preparation)

You create:

  • Collection
  • Requests (GET, POST, etc.)
  • Tests (JavaScript)
  • Environment variables

πŸ‘‰ Example:

  • POST /orders
  • Validate response = 200
  • Save order ID

Step 2 β€” Export from Postman

You export:

  • Collection β†’ collection.json
  • Environment β†’ dev.json

Step 3 β€” Run with Newman

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

Step 4 β€” Integrate into CI/CD

Example pipeline:

  1. Build app
  2. Deploy app
  3. Run Newman
  4. If failed β†’ stop deployment

Key Difference (VERY IMPORTANT)

Feature Postman Newman
UI Yes No
Manual testing Yes No
Automation Limited Yes
CI/CD usage No Yes
DevOps usage Design/testing Automation

Real Example (Your Kafka project)

In Postman:

You create:

  • POST /orders
  • GET /orders
  • Add tests

In Newman (CI/CD):

newman run kafka-tests.json -e prod.json
Enter fullscreen mode Exit fullscreen mode

Pipeline checks:

  • API works
  • Kafka works
  • DB works

If not:
❌ Deployment fails


Why DevOps MUST use Newman

Because DevOps:

  • Cannot manually click Postman every deployment
  • Needs automation
  • Needs repeatable tests

πŸ‘‰ Newman makes API testing:

  • Scriptable
  • Repeatable
  • Pipeline-ready

Installation

npm install -g newman
Enter fullscreen mode Exit fullscreen mode

Interview Answer (short, perfect)

β€œPostman is used for designing and manually testing APIs, while Newman is used to run Postman collections from the command line. In DevOps, we use Newman in CI/CD pipelines to automate API validation after deployments.”

Top comments (0)