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
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.
fetchNewOrleansWeather function with console.log()script.js, create a function called fetchNewOrleansWeatherconsole.log("Weather for New Orleans") inside the function function fetchNewOrleansWeather() {
console.log("Weather for New Orleans");
}
fetchNewOrleansWeather() and press Enter function fetchNewOrleansWeather() {
console.log("Fetch weather for New Orleans");
}
fetchNewOrleansWeather();
💡 Need help with functions? Check out our JavaScript Reference for function basics.
fetchNewOrleansWeatherlatitude=29.95&longitude=-90.07¤t_weather=truefetchNewOrleansWeather function, replacing the console.logfetchNewOrleansWeather() → verify JSON responseapi.open-meteo.com on each call💡 Understanding
.then()and promises? See our Promise Reference Guide for detailed explanations.</summary>
</details>



For each new city:
fetchSeattleWeather, fetchNYCWeather)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.
latitude=29.95&longitude=-90.07latitude=47.61&longitude=-122.33latitude=40.71&longitude=-74.01latitude=34.05&longitude=-118.24latitude=41.88&longitude=-87.63latitude=25.76&longitude=-80.19latitude=39.74&longitude=-104.99latitude=25.03&longitude=121.57fetchNewOrleansWeather, fetchSeattleWeatherYou built weather functions with:
📚 Reference: Promise Reference Guide - Keep this handy for arrow functions and promise concepts!
👉 Next time: replace console.log() with DOM updates (write temperature into a <span>) and add a tiny “Loading…” indicator.