DEV Community

Cover image for API Testing with Postman: How to Test APIs Without Writing Code
kihuni
kihuni

Posted on

API Testing with Postman: How to Test APIs Without Writing Code

Test APIs Like a Pro—No Code Needed in Just 15 Minutes

APIs power our apps—think live weather updates or user profiles. But what happens when they fail? Unexpected errors, broken integrations, and frustrated users. That’s where Postman comes in: a powerful, code-free tool for testing APIs efficiently.

I’ve spent hours debugging APIs, and I know the struggle. Today, I’ll guide you from sending your first request to automating tests in just 15 minutes. By the end, you’ll test APIs with confidence.

Ready? Let’s dive in.

Prerequisites

Here’s what you’ll need to follow along:

Step 1: Getting Started with Postman

Launch Postman—you’re greeted with a clean, empty workspace.

Launch postman

Click “New” (top left) → “HTTP Request.” You now have a blank request ready for action.

New request

Step 2: Sending Your First API Request

Let’s fetch London’s weather using the OpenWeather API.

  1. Set the Method: Keep it as “GET” (default).
  2. Enter the URL: http://api.openweathermap.org/data/2.5/weather?q=London&appid=your_api_key_here&units=metric— swap “your_api_key_here” with your key.

  3. Hit Send: Your response should look something like this:

Weather changes

Error? A 401 Unauthorized likely means your API key is wrong—double-check it. Copy-pasting helps avoid typos! 😌

Step 3: Adding Tests to Verify Results

Let’s automate validation by adding test scripts.

1️⃣ Click the “Tests” tab (below the request bar).
2️⃣ Add this JavaScript snippet:

pm.test("Status is 200", () => {
    pm.response.to.have.status(200);
});
pm.test("City matches", () => {
    const jsonData = pm.response.json();
    pm.expect(jsonData.name).to.eql("London");
});
Enter fullscreen mode Exit fullscreen mode

tests request

3️⃣ Hit “Send” again. Scroll down to the Test Results tab—you should see ✅ “2/2 passed” confirming that the API works!

test

Step 4: Automating Tests with Collections

Why stop at one? Let’s automate multiple tests.

1️⃣ Save your request as “London Weather” to a new collection called “Weather Tests” and click “Save”.

collection

2️⃣ Add a second request for Nairobi:

http://api.openweathermap.org/data/2.5/weather?q=Nairobi&appid=your_api_key_here&units=metric.

Enter fullscreen mode Exit fullscreen mode

Nairobi weather

3️⃣ Modify the test script, replacing “London” with “Nairobi”.

pm.test("Status is 200", () => {
    pm.response.to.have.status(200);
});
pm.test("City matches", () => {
    const jsonData = pm.response.json();
    pm.expect(jsonData.name).to.eql("Nairobi");
});
Enter fullscreen mode Exit fullscreen mode

Weather test

4️⃣ In the Collections tab, find “Weather Tests”, click the three dots (⋮), and select “Run Collection.”

📌 Postman will execute both requests automatically, checking multiple locations in one go!

postman

Conclusion

In just 15 minutes, you’ve gone from sending a single API request to automating tests like a pro—without writing a single backend script. 🎯

Next steps?
🔹 Try testing your APIs.
🔹 Explore Postman’s pre-request scripts and variables for advanced automation.
🔹 Check out Postman’s official docs for deeper insights.

Now go break (and fix) some APIs! 🚀

Top comments (0)