<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ilias Karim’s tech blog]]></title><description><![CDATA[Ilias Karim’s tech blog]]></description><link>https://iliaskarim.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 07:06:01 GMT</lastBuildDate><atom:link href="https://iliaskarim.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Retrieve the Current Weather Forecast from OpenWeather]]></title><description><![CDATA[In this tutorial we will learn how to retrieve the current weather forecast from OpenWeather’s Weather API. OpenWeather offers this API under a freemium business model and requires no payment details to begin using it. This makes OpenWeather an ideal...]]></description><link>https://iliaskarim.dev/how-to-retrieve-the-current-weather-forecast-from-openweather</link><guid isPermaLink="true">https://iliaskarim.dev/how-to-retrieve-the-current-weather-forecast-from-openweather</guid><category><![CDATA[General Programming]]></category><category><![CDATA[APIs]]></category><dc:creator><![CDATA[Ilias Karim]]></dc:creator><pubDate>Mon, 24 Nov 2025 11:58:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1734148109336/785be553-f44e-434b-9742-51b3386a50b9.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this tutorial we will learn how to retrieve the current weather forecast from <a target="_blank" href="https://openweathermap.org/api">OpenWeather’s Weather API</a>. OpenWeather offers this API under a freemium business model and requires no payment details to begin using it. This makes OpenWeather an ideal service to use to learn about making real-world API requests and integrating external data into your applications.</p>
<h2 id="heading-getting-started">Getting Started</h2>
<p>OpenWeather’s <a target="_blank" href="https://openweathermap.org/current">current weather endpoint</a> has three required parameters: <code>appid</code>, <code>lat</code> and <code>lon</code>. These correspond to your application’s API key and the latitude and longitude of the location you want to retrieve the weather forecast for.</p>
<p>To get an API key for <code>appid</code> you will need to <a target="_blank" href="https://home.openweathermap.org/users/sign_up">create an account</a> and <a target="_blank" href="https://home.openweathermap.org/api_keys">generate an API</a> key from OpenWeather. For <code>lat</code> and <code>lon</code>, you can drop a pin in any map app or use <a target="_blank" href="https://openweathermap.org/api/geocoding-api">OpenWeather’s Geocoding API</a> to look up a city or zip code.</p>
<p>In addition to the required parameters, you should also choose the <a target="_blank" href="https://openweathermap.org/weather-data">units format</a> —passed as the <code>units</code> parameter—which can be <code>metric</code> (°C, m/s), <code>imperial</code> (°F, mph), or <code>standard</code> (Kelvin, m/s), the default. Atmospheric pressure, precipitation, and visibility are always reported in hPa, mm, and m regardless of the units you choose.</p>
<h2 id="heading-using-the-current-weather-endpoint"><strong>Using the Current Weather Endpoint</strong></h2>
<p>Now that you have your query parameters, you can make a request. Just specify your application’s API key, GPS coordinates, and measurement units as query parameters.</p>
<p>Here is a complete example:</p>
<p><code>curl -s https://api.openweathermap.org/data/2.5/weather?appid=YOUR_API_KEY&amp;lat=40.6501&amp;lon=-73.9496&amp;units=imperial | jq</code></p>
<p>This command returns a response like this:</p>
<pre><code class="lang-json">{
    <span class="hljs-attr">"coord"</span>: {
        <span class="hljs-attr">"lon"</span>: <span class="hljs-number">-73.9496</span>,
        <span class="hljs-attr">"lat"</span>: <span class="hljs-number">40.6501</span>
    },
    <span class="hljs-attr">"weather"</span>: [
        {
            <span class="hljs-attr">"id"</span>: <span class="hljs-number">801</span>,
            <span class="hljs-attr">"main"</span>: <span class="hljs-string">"Clouds"</span>,
            <span class="hljs-attr">"description"</span>: <span class="hljs-string">"few clouds"</span>,
            <span class="hljs-attr">"icon"</span>: <span class="hljs-string">"02n"</span>
        }
    ],
    <span class="hljs-attr">"base"</span>: <span class="hljs-string">"stations"</span>,
    <span class="hljs-attr">"main"</span>: {
        <span class="hljs-attr">"temp"</span>: <span class="hljs-number">30.81</span>,
        <span class="hljs-attr">"feels_like"</span>: <span class="hljs-number">23.36</span>,
        <span class="hljs-attr">"temp_min"</span>: <span class="hljs-number">28.02</span>,
        <span class="hljs-attr">"temp_max"</span>: <span class="hljs-number">32.13</span>,
        <span class="hljs-attr">"pressure"</span>: <span class="hljs-number">1043</span>,
        <span class="hljs-attr">"humidity"</span>: <span class="hljs-number">42</span>,
        <span class="hljs-attr">"sea_level"</span>: <span class="hljs-number">1043</span>,
        <span class="hljs-attr">"grnd_level"</span>: <span class="hljs-number">1042</span>
    },
    <span class="hljs-attr">"visibility"</span>: <span class="hljs-number">10000</span>,
    <span class="hljs-attr">"wind"</span>: {
        <span class="hljs-attr">"speed"</span>: <span class="hljs-number">8.05</span>,
        <span class="hljs-attr">"deg"</span>: <span class="hljs-number">340</span>
    },
    <span class="hljs-attr">"clouds"</span>: {
        <span class="hljs-attr">"all"</span>: <span class="hljs-number">20</span>
    },
    <span class="hljs-attr">"dt"</span>: <span class="hljs-number">1734137918</span>,
    <span class="hljs-attr">"sys"</span>: {
        <span class="hljs-attr">"type"</span>: <span class="hljs-number">2</span>,
        <span class="hljs-attr">"id"</span>: <span class="hljs-number">2037026</span>,
        <span class="hljs-attr">"country"</span>: <span class="hljs-string">"US"</span>,
        <span class="hljs-attr">"sunrise"</span>: <span class="hljs-number">1734091893</span>,
        <span class="hljs-attr">"sunset"</span>: <span class="hljs-number">1734125346</span>
    },
    <span class="hljs-attr">"timezone"</span>: <span class="hljs-number">-18000</span>,
    <span class="hljs-attr">"id"</span>: <span class="hljs-number">5110302</span>,
    <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Brooklyn"</span>,
    <span class="hljs-attr">"cod"</span>: <span class="hljs-number">200</span>
}
</code></pre>
<p>Here are the key fields and their meanings:</p>
<ol>
<li><p><code>coord</code>: Contains the geographical coordinates of the location. These may differ from the coordinates in the request.</p>
<ul>
<li><p><code>lat</code>: Latitude of the location.</p>
</li>
<li><p><code>lon</code>: Longitude of the location.</p>
</li>
</ul>
</li>
<li><p><code>weather</code>: An array of weather condition objects that in most cases will contain just a single element. In cases where the array contains more than one element the first element in the array should be considered primary.</p>
<ul>
<li><p><code>id</code>: Weather condition ID.</p>
</li>
<li><p><code>main</code>: Group of weather parameters (e.g., Rain, Snow, Extreme, etc.).</p>
</li>
<li><p><code>description</code>: Weather condition within the group.</p>
</li>
<li><p><code>icon</code>: Weather icon ID.</p>
</li>
</ul>
</li>
<li><p><code>base</code>: Internal parameter used by OpenWeather.</p>
</li>
<li><p><code>main</code>: Contains main weather data.</p>
<ul>
<li><p><code>temp</code>: Current temperature.</p>
</li>
<li><p><code>feels_like</code>: Human perception of weather temperature.</p>
</li>
<li><p><code>temp_min</code>: Minimum temperature at the moment.</p>
</li>
<li><p><code>temp_max</code>: Maximum temperature at the moment.</p>
</li>
<li><p><code>pressure</code>: Atmospheric pressure in hectopascals.</p>
</li>
<li><p><code>humidity</code>: Humidity percentage.</p>
</li>
</ul>
</li>
<li><p><code>visibility</code>: Visibility in meters.</p>
</li>
<li><p><code>wind</code>: Contains wind information.</p>
<ul>
<li><p><code>speed</code>: Wind speed.</p>
</li>
<li><p><code>deg</code>: Wind direction in degrees.</p>
</li>
</ul>
</li>
<li><p><code>clouds</code>: Cloudiness percentage.</p>
<ul>
<li><code>all</code>: Cloudiness percentage.</li>
</ul>
</li>
<li><p><code>rain</code>: Rain volume.</p>
<ul>
<li><p><code>1h</code>: Rain volume for the last 1 hour (if available).</p>
</li>
<li><p><code>3h</code>: Rain volume for the last 3 hours (if available).</p>
</li>
</ul>
</li>
<li><p><code>snow</code>: Snow volume.</p>
<ul>
<li><p><code>1h</code>: Snow volume for the last 1 hour (if available).</p>
</li>
<li><p><code>3h</code>: Snow volume for the last 3 hours (if available).</p>
</li>
</ul>
</li>
<li><p><code>dt</code>: Time of data calculation, Unix timestamp.</p>
</li>
<li><p><code>sys</code>: Contains additional information.</p>
<ul>
<li><p><code>type</code>: Internal parameter.</p>
</li>
<li><p><code>id</code>: Internal parameter.</p>
</li>
<li><p><code>country</code>: Country code.</p>
</li>
<li><p><code>sunrise</code>: Sunrise time, Unix timestamp.</p>
</li>
<li><p><code>sunset</code>: Sunset time, Unix timestamp.</p>
</li>
</ul>
</li>
<li><p><code>timezone</code>: Shift in seconds from UTC.</p>
</li>
<li><p><code>id</code>: City ID.</p>
</li>
<li><p><code>name</code>: City name.</p>
</li>
<li><p><code>cod</code>: Internal parameter indicating the status of the response.</p>
</li>
</ol>
<p>Including <code>weather</code>, the Current Weather endpoint returns up to fifteen other top-level fields. Two of these—<code>base</code> and <code>cod</code>—are internal parameters, and two—<code>rain</code> and <code>snow</code>—are objects that may be omitted if no precipitation occurs.</p>
<p>The remaining top-level fields are <code>coord</code>, <code>main</code>, <code>visibility</code>, <code>wind</code>, <code>clouds</code>, <code>dt</code>, <code>sys</code>, <code>timezone</code>, <code>id</code>, and <code>name</code>. Of these, <code>visibility</code>, <code>dt</code>, <code>timezone</code>, <code>id</code>, and <code>name</code> are simple values, while the rest (<code>coord</code>, <code>main</code>, etc.) are objects with their own nested fields.</p>
<p>These fields provide a comprehensive overview of the current weather conditions at a specified location.</p>
<h3 id="heading-displaying-weather-icons">Displaying Weather Icons</h3>
<p>Each weather condition object includes an ID (<code>id</code>), a title (<code>main</code>), a short description (<code>description</code>), and an icon ID (<code>icon</code>). To get the corresponding image, append the icon ID to <a target="_blank" href="https://openweathermap.org/img/wn/"><code>https://openweathermap.org/img/wn/</code></a> and add <code>@2x.png</code> for retina resolution or <code>.png</code> for standard resolution.</p>
<p>OpenWeather provides a full list of <a target="_blank" href="https://openweathermap.org/weather-conditions">weather codes</a>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>We’ve seen how to pull the current weather forecast from OpenWeather, explored the response fields, and learned how to turn icon IDs into image URLs. With these pieces in place, we can start building apps that show real-time weather or visualize this data in dashboards. There’s even a 5-day forecast endpoint if you want to go further.</p>
<p><em>Photo credit: Shutterstock</em></p>
]]></content:encoded></item></channel></rss>