How do I get current weather data via OpenWeather REST API?

An example of getting the current weather data for a selected city via a free REST API weather service. Public weather REST API service provided by OpenWeatherMap.org. The weather REST API key and city name are passed as URL parameters. The weather REST API service can be requested with HTTP GET requests.
How do I get current weather data via OpenWeather REST API? Send
GET /data/2.5/weather?appid={openweathermap_apikey}&q=chicago HTTP/1.1
Host: api.openweathermap.org
Accept: application/json

Updated: Viewed: 34017 times

How to request the Weather REST API service?

To get weather data via the REST API service, you need to make an HTTP GET request to the weather REST API endpoint and provide your free weather REST API key and city name as URL parameters.

https://api.openweathermap.org/data/2.5/weather?appid={apikey}&q=chicago

You can also get current weather data by geographic coordinates by postcode by specifying latitude and longitude or postal code in the URL. Check the example below.

https://api.openweathermap.org/data/2.5/weather?appid={apikey}&lat=35&lon=139
https://api.openweathermap.org/data/2.5/weather?appid={apikey}&zip=94040,us

Types of weather data that can be retrieved by the Weather REST API

The Weather REST API service provides the following types of weather data:
  • Current Weather Data - current weather data for over 200,000 cities in JSON, XML and HTML formats.
  • Hourly Forecast 4 days - 4-day hourly weather forecast with higher geographical accuracy in JSON and XML formats.
  • Daily Forecast for 16 days - weather forecast for 16 days for any place and city in JSON and XML formats.
  • Climatic Forecast 30 days - weather forecast for 30 days in JSON format
  • 5 Day / 3 Hour Forecast - 5-day weather forecast for any location or city in JSON and XML formats

Generate Code Snippets for Weather REST API Example

Convert your Weather REST API request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the ReqBin code generator.