Weather forecasting applications have always been invaluable tools for everyone as the climate is susceptible to unforeseen changes at any time. Many industry sectors integrate these applications into their information systems to assist them in various tasks such as business and event planning, taking safety measures, and informed decisions based on weather information. Due to that, there is an increasing demand for accurate weather information and forecasting applications worldwide.
If you are a developer planning to build a weather forecasting application, you can integrate an API to retrieve the required weather data instead of building it from scratch. ClimaCell API is one of the top free weather APIs that enables you to accomplish that.
What is the ClimaCell API?
ClimaCell API is an all-in-one weather API that allows you to retrieve accurate weather information at a specific location. It has been developed based on ClimaCell’s proprietary technology. Furthermore, this API can be used to retrieve real-time weather information at a particular location, global hourly forecasts, and forecasting data on a minute-by-minute basis. Based on this weather information, you can generate invaluable insights and drive actions accordingly.
Currently, ClimaCell API has three pricing plans and a free subscription. It supports a variety of programming languages, including Python, PHP, Ruby, and Javascript. In this article, we will dive deeper into this API and see how to use it with multiple programming languages.
How does the ClimaCell API work?
ClimaCell API works using a simple API logic in which it sends a request to a specific endpoint and obtains the necessary output as the response. When sending a request, it includes x-RapidAPI-key and host as authentication parameters so that the server can identify it as a valid request. The body of the API request contains the latitude and longitude of the location and any optional parameters users specify. Once the API server has received the request, it will process the request using the back-end application with ClimaCell’s proprietary sensing technology and model. Finally, the server will send back the weather information requested by the client in JSON format.
Target Audience for the ClimaCell API
Weather Application Developers
Weather forecasting applications are used in many industries, including aviation, agriculture, and construction industries. Most of them use weather dashboards and applications that are capable of sending hourly and minute-by-minute weather forecasts for their workers. ClimaCell API provides the exact capabilities those applications require. Since this API has three pricing plans, they have the choice to select the best option based on their requirements.
Chatbot Developers
Chatbot developers who are looking to support weather queries in their chatbot applications can use this API coupled with NLP. For example, suppose a user wants to find a certain weather metric of a particular city at a specific time. In that case, the combination of ClimaCell API Realtime and Nowcast endpoints will be useful and requires a minimum code for the integration. ClimaCell will be compatible with many chatbot applications since it supports a number of programming languages.
Utility Companies
Consumer demand for utilities like electricity, telecommunication, and gas are highly affected by the weather. The reason is that their demand fluctuates based on the current weather metrics like temperature, wind, and humidity. Therefore utility companies, with the help of application developers, can build their applications to predict the consumer demand based on the weather and plan their purchases and deliveries accordingly. ClimaCell API is an easy-to-use API that they can utilize in such applications.
How to connect to the ClimaCell API Tutorial – Step by Step
Step 1 – Sign up and Get a RapidAPI Account.
RapidAPI is the world’s largest API marketplace which is used by more than a million developers worldwide. You can use it to search and connect to thousands of APIs using a single SDK, API key, and Dashboard.
To create a RapidAPI account, go to rapidapi.com and click on the Sign Up icon. You can use your Google, Github, or Facebook account for Single Sign-on (SSO) or create an account manually.
Step 2 – Search the API Marketplace
Navigate to the Marketplace and search for “Weather APIs.” Then, select the ‘ClimaCell’ API from the search results.
Step 3 – Subscribe to the API
We need to subscribe to ClimaCell API to use it. Navigate to the “pricing” section of the API and subscribe to your preferred plan. For the purpose of this article, we select the basic free plan of the API. Then, simply click on the “subscribe” button to activate the subscription.
Step 4 – Test the API Subscription
After subscribing to the API, you should run a test for the endpoints. For that, navigate to the ‘Endpoints’ section of the API page which displays all the available endpoints.
Next, select the API endpoint you want to test and add the required values for the parameters. Each endpoint has code snippets in multiple languages, and they automatically add the API keys.
Finally, click on the “Test Endpoint” Button to test the endpoint. You will get the response with a 200 status code upon successful testing of an endpoint. On the other hand, it will output an error code and message if there is an error in the request.
The ClimaCell API Endpoints
Currently, RapidAPI provides three endpoints for the ClimaCell API.
Realtime
This API endpoint provides real-time weather information. It is accessible using GET and requires two mandatory parameters as follows.
- ‘lat’ – latitude of the location.
- ‘lon’ – longitude of the location
In addition to the above parameters, you can also use optional parameters such as the ‘unit_system,’ which specifies the unit of the weather measurement and the ‘fields’ or the weather elements you want to fetch from the API. For instance, ‘precipitation,’ wind_gust,’ ‘wind_speed, and ‘temp’ for temperature. You can find the full list of values for the ‘fields’ parameter at https://www.climacell.co/weather-api/docs/. The response for a call for this endpoint looks like the following.
Hourly
This API endpoint provides a global hourly weather forecast for a specific location up to 96 hours, which can be accessed using GET. Apart from the mandatory latitude and longitude parameters, you can also define optional parameters such as the unit system, fields, and the end time. The End-time should be written in ISO8601 format. For example, “2021-05-25T20:00:00Z”. As the response, you will get an array of hourly weather measurement values up to the end time you specified. The following figure shows an example of the usage of the hourly endpoint. Moreover, it will give you hourly forecasts for up to 4 days if you did not include an end time.
Nowcast
This API GET endpoint provides short-term weather forecasting data on a minute-by-minute basis based on ClimaCell’s proprietary sensing technology and model. Mandatory and optional parameters are the same as in hourly forecast endpoints.
Integrating the ClimaCell API to an Application
In this section, we will illustrate how to integrate the ClimaCell API into Python, PHP, Ruby, and Javascript software applications using sample code snippets. For this instance, we will be using the “GET Realtime” endpoint for all the code snippets. In the header of each code, you need to include the ‘X-RapidAPI-key and X-RapidAPI-host parameters which you can obtain from the API page.
Python (requests)
In the following Python code, the “requests” library is used to send a GET request to the endpoint. Hence, you need to first install the module on your computer. All the parameters are specified in the “querystring” variable. The request method of the request object sends the API call. You can also use requests.post method for this purpose.
import requests url = "https://climacell-microweather-v1.p.rapidapi.com/weather/realtime" querystring = {"lat":"42.8237618","lon":"-71.2216286","unit_system":"si","fields":"humidity"} headers = { 'x-rapidapi-key': "cJvLRNK0GfdM9WSMbQe3inU7REn8JVy5", 'x-rapidapi-host': "climacell-microweather-v1.p.rapidapi.com" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
PHP (HTTP v2)
We use HTTP v2 to send the request in a PHP application. First, you need to create client and request class objects. Then you need to set the API URL and the request method separately to the request object. Next, create a new QueryString object including all the parameters and set it to the request. Finally, send the request through the send method of the client object. You can also use cURL, HTTP V1, and Unirest/Request code snippets provided on the API website.
<?php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://climacell-microweather-v1.p.rapidapi.com/weather/realtime'); $request->setRequestMethod('GET'); $request->setQuery(new http\QueryString([ 'lat' => '42.8237618', 'lon' => '-71.2216286', 'unit_system' => 'si', 'fields' => 'humidity' ])); $request->setHeaders([ 'x-rapidapi-key' => 'cJvLRNK0GfdM9WSMbQe3inU7REn8JVy5', 'x-rapidapi-host' => 'climacell-microweather-v1.p.rapidapi.com' ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();
Ruby (net::http)
If you are using the net::http module in Ruby, import ‘openssl’, and ‘uri’ modules at the beginning. In this instance, bypass SSL certification verification by setting it to ‘VERIFY_NONE’. Unlike in the above code examples, you can directly set the parameters in the query string along with the URL.
require 'uri' require 'net/http' require 'openssl' url = URI("https://climacell-microweather-v1.p.rapidapi.com/weather/realtime?lat=42.8237618&lon=-71.2216286&unit_system=si&fields=humidity") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'cJvLRNK0GfdM9WSMbQe3inU7REn8JVy5' request["x-rapidapi-host"] = 'climacell-microweather-v1.p.rapidapi.com' response = http.request(request) puts response.read_body
Javascript (Axios)
Integrating ClimaCell API into a Javascript application is fairly easy. The following code snippet shows how to call this API using its ‘axios’ module. You can define the parameters, URL, headers, and the request method in one Javascript object and use axios.request method to send the request and retrieve the response.
import axios from "axios"; const options = { method: 'GET', url: 'https://climacell-microweather-v1.p.rapidapi.com/weather/realtime', params: {lat: '42.8237618', lon: '-71.2216286', unit_system: 'si', fields: 'humidity'}, headers: { 'x-rapidapi-key': 'cJvLRNK0GfdM9WSMbQe3inU7REn8JVy5', 'x-rapidapi-host': 'climacell-microweather-v1.p.rapidapi.com' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); });
Alternatives to the ClimaCell API
Weather API – A powerful API that provides several endpoints for different types of weather data. For example, weather forecast, historical weather, astronomy, as well as other capabilities like IP lookup, and upcoming sports events, and autocomplete.
Open Weather Map – This API provides several endpoints to get weather and weather forecasts for multiple cities, which include current and historical data.
Weather – This API can be used to get severe weather alerts and 120 hours, 16 days, 5 days, and minutely weather forecasts.
Dark Sky – This API includes endpoints that return the historical or forecasted hour-by-hour weather and daily weather conditions for a particular date.
Visual Crossing Weather – This API provides hourly, 12 hour and daily weather forecast up to seven days and historical weather information.
Benefits of the ClimaCell API
High Accuracy
Accuracy is the most important feature of a weather application. ClimaCell uses a hybrid of traditional weather sources and their sensing technology which consists of a large number of IoT sensors and cell towers. Therefore, this API is capable of providing more accurate and reliable weather information.
Easy to Integrate
With the ClimaCell API, you need to pass just a few parameters with the request. As a result, you do not have to spend a lot of time writing complicated code. Besides, you can find example code snippets in many programming languages with two or more frameworks or modules. Due to this simplicity, even someone with little to no background using APIs can master the API fairly quickly.
Widespread Usage
These API endpoints enable you to get not only the basic weather measurements like temperature and humidity but also many other weather measurements like wind speed, wind gust, and pollen data. Due to that, this API is widely used and can be easily integrated into many types of weather applications.
Summary
ClimaCell API is a powerful and easy-to-use weather API that can be used to retrieve real-time weather data and forecasts of a particular location. You can get various weather measurements using this API. In this article, we discussed how to subscribe to it, its available endpoints, benefits, target audience, and provided sample code snippets in Python, PHP, Ruby, and Javascript to show how to use it in an application.
Leave a Reply