openweathermap
Module openweathermap
![](https://bcentral-packageicons.azureedge.net/images/ballerinax_openweathermap_1.5.0.png)
ballerinax/openweathermap Ballerina library
Overview
This is a generated connector from Open Weather Map API v2.5 OpenAPI Specification.
The Open Weather Map API provides access to current weather data and weather forecast of any location worldwide including 200,000 cities by consuming the Current Weather Data
and One Call
API endpoints.
Prerequisites
- Create OpenWeatherMap account.
- Choose a subscription that matches with your requirements
- Obtain Api Key
- Visit My API Keys and generate a new API Key
Quickstart
To use the Open Weather Map connector in your Ballerina application, update the .bal file as follows:
Step 1: Import connector
import ballerinax/openweathermap;
Step 2: Create a new connector instance
Provide the obtained API Key in client configuration.
openweathermap:ApiKeysConfig config = { appid : "<your appid>" }; openweathermap:Client openweatherClient = check new Client(config);
Step 3: Invoke connector operation
- Obtain current weather data by city name.
openweathermap:CurrentWeatherData result = check openweatherClient->getCurretWeatherData("Colombo"); log:printInfo("Colombo Current Weather data : " + result.toString());
- Use
bal run
command to compile and run the Ballerina program.
Clients![](/images/permalink.svg)
openweathermap: Client![](/images/permalink.svg)
This is a generated connector from Open Weather Map API version 2.5 OpenAPI Specification.
The Open Weather Map API provides access to current weather data and weather forecast of any location worldwide including 200,000 cities by consuming the Current Weather Data
and One Call
API endpoints.
Constructor![](/images/permalink.svg)
Gets invoked to initialize the connector
.
The connector initialization requires setting the API credentials.
Please create an account at https://openweathermap.org and an API key following this guide. Choose a subscription that matches with your requirements.
init (ApiKeysConfig apiKeyConfig, ConnectionConfig config, string serviceUrl)
- apiKeyConfig ApiKeysConfig - API keys for authorization
- config ConnectionConfig {} - The configurations to be used when initializing the
connector
- serviceUrl string "http://api.openweathermap.org/data/2.5/" - URL of the target service
getCurretWeatherData![](/images/permalink.svg)
function getCurretWeatherData(string? q, string? id, string? lat, string? lon, string? zip, string units, string lang, string mode) returns CurrentWeatherData|error
Access current weather data for any location. Note: All parameters are optional, but you must provide at least one parameter. Calling the API by city ID (using the id
parameter) will provide the most precise location results.
Parameters
- q string? (default ()) - City name, or city name and country code. For the query value, type the city name and optionally the country code divided by comma; use ISO 3166 country codes.
- lat string? (default ()) - Latitude
- lon string? (default ()) - Longtitude
- zip string? (default ()) - Zip code. Search by zip code. Example: 95050,us.
- units string (default "imperial") - Temperature in Fahrenheit use
units=imperial
, temperature in Celsius useunits=metric
, temperature inKelvin
is used by default.
- lang string (default "en") - Language
- mode string (default "json") - Format of response. Possible values are
xml
andhtml
. If mode parameter is empty the format isjson
by default.
Return Type
- CurrentWeatherData|error - Current weather data of the given location
getWeatherForecast![](/images/permalink.svg)
function getWeatherForecast(string lat, string lon, string? exclude, string? units, string? lang) returns WeatherForecast|error
Access to current weather, minute forecast for 1 hour, hourly forecast for 48 hours, daily forecast for 7 days and government weather alerts.
Parameters
- lat string - Latitude
- lon string - Longtitude
- exclude string? (default ()) - Exclude parts of the weather data from the API response. It should be a comma-delimited list (without spaces).
- units string? (default ()) - For temperature in Fahrenheit and wind speed in miles/hour, use
units=imperial
. For temperature in Celsius and wind speed in meter/sec, useunits=metric
. Temperature in Kelvin and wind speed in meter/sec is used by default, so there is no need to use the units parameter in the API call if you want this.
- lang string? (default ()) - Language
Return Type
- WeatherForecast|error - Weather forecast of the given location
Records![](/images/permalink.svg)
openweathermap: Alerts![](/images/permalink.svg)
Government weather alerts
Fields
- sender_name string? - Name of the alert source.
- event string? - Alert event name
- description string? - Description of the alert
- 'start decimal? - Date and time of the start of the alert, Unix, UTC
- end decimal? - Date and time of the end of the alert, Unix, UTC
- tags string[]? - Tags related to alerts
openweathermap: ApiKeysConfig![](/images/permalink.svg)
Provides API key configurations needed when communicating with a remote HTTP endpoint.
Fields
- appid string - Represents API Key
appid
openweathermap: ClientHttp1Settings![](/images/permalink.svg)
Provides settings related to HTTP/1.x protocol.
Fields
- keepAlive KeepAlive(default http:KEEPALIVE_AUTO) - Specifies whether to reuse a connection for multiple requests
- chunking Chunking(default http:CHUNKING_AUTO) - The chunking behaviour of the request
- proxy ProxyConfig? - Proxy server related options
openweathermap: Clouds![](/images/permalink.svg)
Nature of the clouds
Fields
- all int? - Cloudiness, %
openweathermap: ConnectionConfig![](/images/permalink.svg)
Provides a set of configurations for controlling the behaviours when communicating with a remote HTTP endpoint.
Fields
- httpVersion HttpVersion(default http:HTTP_2_0) - The HTTP version understood by the client
- http1Settings ClientHttp1Settings? - Configurations related to HTTP/1.x protocol
- http2Settings ClientHttp2Settings? - Configurations related to HTTP/2 protocol
- timeout decimal(default 60) - The maximum time to wait (in seconds) for a response before closing the connection
- forwarded string(default "disable") - The choice of setting
forwarded
/x-forwarded
header
- poolConfig PoolConfiguration? - Configurations associated with request pooling
- cache CacheConfig? - HTTP caching related configurations
- compression Compression(default http:COMPRESSION_AUTO) - Specifies the way of handling compression (
accept-encoding
) header
- circuitBreaker CircuitBreakerConfig? - Configurations associated with the behaviour of the Circuit Breaker
- retryConfig RetryConfig? - Configurations associated with retrying
- responseLimits ResponseLimitConfigs? - Configurations associated with inbound response size limits
- secureSocket ClientSecureSocket? - SSL/TLS-related options
- proxy ProxyConfig? - Proxy server related options
- validation boolean(default true) - Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
openweathermap: Coord![](/images/permalink.svg)
City geo location
Fields
- lon decimal? - Longitude
- lat decimal? - Latitude
openweathermap: CurrentWeatherData![](/images/permalink.svg)
Current weather data
Fields
- coord Coord? - City geo location
- weather Weather[]? - More info Weather condition codes
- base string? - Internal parameter
- main Main? - Basic weather data
- visibility int? - Visibility, meter
- wind Wind? - Nature of the wind
- clouds Clouds? - Nature of the clouds
- rain Rain? - Nature of the rain
- snow Snow? - Snow volume information
- dt int? - Time of data calculation, unix, UTC
- sys Sys? - System data
- id int? - City ID
- name string? - City name
- cod int? - Internal parameter
openweathermap: Daily![](/images/permalink.svg)
Daily forecast weather data API response
Fields
- dt decimal? - Time of the forecasted data, Unix, UTC
- temp Temp? - Temperature data
- feels_like FeelsLike? - Human perception of temperature each time of the day
- moonrise decimal? - The time of when the moon rises for this day, Unix, UTC
- moonset decimal? - The time of when the moon sets for this day, Unix, UTC
- moon_phase decimal? - Moon phase. 0 and 1 are 'new moon', 0.25 is 'first quarter moon', 0.5 is 'full moon' and 0.75 is 'last quarter moon.
- pressure decimal? - Atmospheric pressure on the sea level, hPa
- humidity decimal? - Humidity, %
- dew_point decimal? - Atmospheric temperature below which water droplets begin to condense and dew can form.
- uvi decimal? - The maximum value of UV index for the day
- clouds decimal? - Cloudiness, %
- visibility decimal? - Visibility of the atmosphere
- wind_deg decimal? - Wind direction, degrees (meteorological)
- wind_gust decimal? - (where available) Wind gust. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour.
- pop decimal? - Probability of precipitation
- weather Weather[]? - More info Weather condition codes
- rain decimal? - where available) Precipitation volume, mm
openweathermap: FeelsLike![](/images/permalink.svg)
Human perception of temperature each time of the day
Fields
- day decimal? - Day temperature.
- night decimal? - Night temperature.
- eve decimal? - Evening temperature.
- morn decimal? - Morning temperature.
openweathermap: ForecastCurrent![](/images/permalink.svg)
Current weather data API response
Fields
- dt decimal? - Current time, Unix, UTC
- sunrise decimal? - Sunrise time, Unix, UTC
- sunset decimal? - Sunset time, Unix, UTC
- temp decimal? - Temperature. Units - default: kelvin, metric: Celsius, imperial: Fahrenheit.
- feels_like decimal? - Temperature. This temperature parameter accounts for the human perception of weather.
- pressure decimal? - Atmospheric pressure on the sea level, hPa
- humidity decimal? - Humidity, %
- dew_point decimal? - Atmospheric temperature below which water droplets begin to condense and dew can form.
- uvi decimal? - Current UV index
- clouds decimal? - Cloudiness, %
- visibility decimal? - Average visibility, metres
- wind_speed decimal? - Wind speed. Wind speed. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour.
- wind_deg decimal? - Wind direction, degrees (meteorological)
- weather Weather[]? - More info Weather condition codes
- rain Rain? - Nature of the rain
- snow Snow? - Snow volume information
openweathermap: Hourly![](/images/permalink.svg)
Hourly forecast weather data API response
Fields
- dt decimal? - Time of the forecasted data, Unix, UTC
- temp decimal? - Temperature. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
- feels_like decimal? - Temperature. This accounts for the human perception of weather.
- pressure decimal? - Atmospheric pressure on the sea level, hPa
- humidity decimal? - Humidity, %
- dew_point decimal? - Atmospheric temperature below which water droplets begin to condense and dew can form.
- uvi decimal? - UV index
- clouds decimal? - Cloudiness, %
- visibility decimal? - Average visibility, metres
- wind_deg decimal? - Wind direction, degrees (meteorological)
- wind_gust decimal? - (where available) Wind gust. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour.
- pop decimal? - Probability of precipitatio
- weather Weather[]? - More info Weather condition codes
- rain Rain? - Nature of the rain
openweathermap: Main![](/images/permalink.svg)
Basic weather data
Fields
- temp decimal? - Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
- pressure int? - Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa
- humidity int? - Humidity, %
- temp_min decimal? - Minimum temperature at the moment.
- temp_max decimal? - Maximum temperature at the moment.
- sea_level decimal? - Atmospheric pressure on the sea level, hPa
- grnd_level decimal? - Atmospheric pressure on the ground level, hPa
openweathermap: Minutely![](/images/permalink.svg)
Minute forecast weather data API response
Fields
- dt decimal? - Time of the forecasted data, unix, UTC
- precipitation decimal? - Precipitation volume, mm
openweathermap: ProxyConfig![](/images/permalink.svg)
Proxy server configurations to be used with the HTTP client endpoint.
Fields
- host string(default "") - Host name of the proxy server
- port int(default 0) - Proxy server port
- userName string(default "") - Proxy server username
- password string(default "") - Proxy server password
openweathermap: Rain![](/images/permalink.svg)
Nature of the rain
Fields
- '3h int? - Rain volume for the last 3 hours
openweathermap: Snow![](/images/permalink.svg)
Snow volume information
Fields
- '3h decimal? - Snow volume for the last 3 hours
openweathermap: Sys![](/images/permalink.svg)
System data
Fields
- 'type int? - Internal parameter
- id int? - Internal parameter
- message decimal? - Internal parameter
- country string? - Country code (GB, JP etc.)
- sunrise int? - Sunrise time, unix, UTC
- sunset int? - Sunset time, unix, UTC
openweathermap: Temp![](/images/permalink.svg)
Temperature data
Fields
- day decimal? - Day temperature.
- min decimal? - Min daily temperature.
- max decimal? - Max daily temperature.
- night decimal? - Night temperature.
- eve decimal? - Evening temperature.
- morn decimal? - Morning temperature
openweathermap: Weather![](/images/permalink.svg)
Weather metadata
Fields
- id int? - Weather condition id
- main string? - Group of weather parameters (Rain, Snow, Extreme etc.)
- description string? - Weather condition within the group
- icon string? - Weather icon id
openweathermap: WeatherForecast![](/images/permalink.svg)
Weather forecast data
Fields
- lat decimal? - Latitude
- lon decimal? - Longtitude
- timezone string? - Timezone name for the requested location
- timezone_offset decimal? - Shift in seconds from UTC
- current ForecastCurrent? - Current weather data API response
- minutely Minutely[]? - Minutely weather forecast
- hourly Hourly[]? - Hourly weather forecast
- daily Daily[]? - Daily weather forecast
- alerts Alerts[]? - Government weather alerts
openweathermap: Wind![](/images/permalink.svg)
Nature of the wind
Fields
- speed decimal? - Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
- deg int? - Wind direction, degrees (meteorological)
Import
import ballerinax/openweathermap;
Metadata
Released date: over 1 year ago
Version: 1.5.0
License: Apache-2.0
Compatibility
Platform: any
Ballerina version: 2201.4.1
GraalVM compatible: Yes
Pull count
Total: 5065
Current verison: 25
Weekly downloads
Keywords
Lifestyle & Entertainment/News & Lifestyle
Cost/Freemium
Contributors
Dependencies