codex-lv2-may-2025

🧪 Lesson 5 — Postman Code Generation

Tags: #lesson #level2 #postman #javascript Goal: Create functions for multiple cities using Postman codegen. Test in Console first, then optionally add buttons. Tools: Postman, browser DevTools (Console + Network), Bootstrap (CDN) - buttons are optional


Overview

In this lesson, you will use your repo from lesson 3.

Postman Code Generation is a powerful feature that automatically converts your API requests into working code snippets. When you click the “Code” button in Postman, it generates ready-to-use JavaScript, Python, or other language code that you can copy and paste directly into your projects.

Instead of having loose API code scattered throughout our script, we’ll create clean, named functions like fetchNewOrleansWeather() that contain all the Postman-generated fetch logic. You’ll first create the function, then immediately call the function to test it.

In this lesson, we will only be logging data to the console. We will update the actual webpage in the next lesson.


Steps

1. Create fetchNewOrleansWeather function with console.log()

Show me:
  function fetchNewOrleansWeather() {
    console.log("Weather for New Orleans");
  }

2. Immediately call it to test it in the console

Show me:
  function fetchNewOrleansWeather() {
    console.log("Fetch weather for New Orleans");
  }
  fetchNewOrleansWeather();
Show me: Console showing log of Weather for New Orleans

💡 Need help with functions? Check out our JavaScript Reference for function basics.

3. Optional Challenge: call when you click on a button

4. Code gen from Postman and paste into fetchNewOrleansWeather

💡 Understanding .then() and promises? See our Promise Reference Guide for detailed explanations.</summary>

Postman Code tab showing JavaScript Fetch code button </details>

Postman Code tab showing JavaScript Fetch code

5. Reload the page and check the network tab and the console tab in dev tools

Console showing JSON weather data response

Network tab showing the API request

6. Repeat for the other cities

For each new city:

7. Analyze network performance

Why this matters: Understanding network performance helps you identify potential bottlenecks and optimize your app. Some cities might load faster than others due to server location, network conditions, or API response times. This analysis gives you real-world insights into how your app performs and helps you make informed decisions about user experience improvements. The console delay gives you a user’s perspective of how “fast” or “slow” the app feels.


City Coordinates Reference


Tips & Testing


Wrap-Up

You built weather functions with:

📚 Reference: Promise Reference Guide - Keep this handy for arrow functions and promise concepts!


🔗 Navigation

👉 Next time: replace console.log() with DOM updates (write temperature into a <span>) and add a tiny “Loading…” indicator.