Skip to content

Chapter 1.5: Testing an API with Postman

Study time: 50 minutes


1. Why Test an API? Pre-launch Check

Imagine: before launching a rocket, engineers conduct test system activations. Skip the check, and the mission could fail!

API testing is your control test:

  • ✅ Check the functionality of the "docking ports"

  • 🛡️ Detect vulnerabilities before live use

  • 📊 Ensure that data is transmitted without distortion

💡 Space analogy: Postman is like a test console at the MCC for simulating all scenarios: "What if we request data about a non-existent planet? Can the server handle 1000 requests/sec?"


2. Postman: The "Mission Control Center" for APIs

Features:

  • 📡 Sending any HTTP requests (GET, POST, PUT, DELETE)

  • 🔍 Analyzing responses (status codes, headers, JSON body)

  • 🧪 Writing automated tests (JavaScript)

  • 🌐 Working with environment variables (test vs. production)

👉 Download Postman


3. First Launch: Testing the Planets API

Step 1: Create a request

  1. Open Postman → New → Request

  2. Enter the URL: https://api.spacexdata.com/v4/rockets

  3. Select the method: GET

Step 2: Send the "signal"

[MCC] -- GET /planets --> [SpaceX Server]

Step 3: Analyze the telemetry: - Status: 200 OK - Response body (JSON): a list of rockets with parameters

[
  {
    "name": "Falcon 1",
    "type": "rocket",
    "active": false,
    "stages": 2,
    "id": "5e9d0d95eda69955f709d1eb"
  },
  {
    "name": "Falcon 9",
    "type": "rocket",
    "active": true,
    "id": "5e9d0d95eda69973a809d1ec"
  }
]


4. Diagram: Postman Components

[Workspace]
├── "Params" tab (Query parameters)
├── "Headers" tab (Headers)
├── "Body" tab (Request body for POST/PUT)
├── "Tests" tab (Scripts for checks)
└── Response panel (Status, Time, Size, Body)

5. Creating a Complex Scenario: Mission Launch

Test: Adding a new planet to the catalog

  1. Method: POST

  2. URL: https://jsonplaceholder.typicode.com/posts (example)

  3. In Headers:

     { "Content-Type": "application/json" }
    

  4. In Body (raw → JSON):
    {
     "title": "New Exoplanet Found",
     "body": "Proxima Centauri b shows signs of a stable atmosphere.",
     "userId": 1
     }
    

Automated check in Tests:

// Status check
pm.test("Post created successfully", () => {
    pm.response.to.have.status(201);
});

// Checking the structure and data of the response
pm.test("Response contains the new post data", () => {
    const response = pm.response.json();
    pm.expect(response).to.have.property("id"); // Check that the server has assigned an ID
    pm.expect(response.title).to.eql("New Exoplanet Found");
});


6. Environment Variables: Earth vs. Mars

How to test on different servers (test/production)?

  1. Create environments:
  2. Localhttp://localhost:3000
  3. Productionhttps://api.nasa.gov

  4. Use variables in requests:

    {{base_url}}/planets  # Will substitute the current URL
    

⚠️ Important! Never test DELETE on a production server!


7. Collections: A Library of Space Missions

Group requests:

    📂 "NASA" Collection
    ├── GET Planets
    ├── POST New Planet
    └── DELETE Planet (test mode)
Advantages:

  • 🚀 Run all tests with one button
  • 📤 Export/import configurations
  • 👨‍🚀 Team collaboration

8. Automation: Regular Satellite Checks

Set up API monitoring via Postman:

  1. Schedule → Every 2 hours

  2. Tests:

    pm.test("Satellite online", () => {
      pm.response.to.have.status(200);
      pm.expect(pm.response.json().signal).above(50); // Signal >50%
    });
    

  3. Notifications to Slack/email on failure


Quiz for reinforcement

1. Postman is used for:

2. What status to expect when an object is created successfully?

3. Where to write automated tests in Postman?

4. Environment variables are needed for:

5. What do regular monitoring checks verify?


🚀 Chapter summary: Postman is your universal "control panel" for API testing. With it you will: - Check the operation of "onboard systems" before launch - Create a library of test scenarios - Automate the monitoring of space services

📌 Practical task:

  1. Install Postman
  2. Create a request to the SpaceX API: GET https://api.spacexdata.com/v4/launches/latest
  3. Write a test that checks that:
  4. The response status is 200
  5. The name field contains the word "Falcon"
  6. The response time is < 500 ms

Congratulations on completing Chapter 1!

You have mastered the basics of working with APIs. In the following chapters, we will build our own "spaceship" - a web application that uses space APIs!

🌌 Additional resources: