Weather plays an important role in all aspects of our lives. Not only do we rely on weather information for planning day-to-day activities like commute or other outdoor activities, but all major events like outdoor entertainment programs/sports matches heavily depend on the weather. Further, airlines, utility companies, fire stations also require accurate weather information. Thus, there is an ever-increasing need for precise weather information for locations all over the world. A number of REST APIs have emerged to satisfy this need. One such weather API is the Visual Crossing Weather API. In this article, we will be learning about this API and its features.
The Visual Crossing Weather API is a forecast and historical weather API by Visual Crossing Corporation. It provides a 16-day global weather forecast. The weather forecast is available on a daily and hourly basis. It is available for all worldwide locations. Further, the API also provides historical weather information. The location can also be specified as a city, state, zip code, complete or partial address as well as a latitude/longitude combination. In addition to location, the endpoints accept a lot of other parameters which can be used to customize the output. The output consists of a number of weather-related fields like the minimum and maximum temperatures, humidity, heat index, wind speed, and direction, etc.
The Visual Crossing Weather API can be used by application developers in different types of web-based/mobile applications. Some of the types of applications that can be built using the API are listed below.
Weather applications – Since weather is so important to people in their day-to-day decision-making, there is a huge need for websites and mobile applications that provide the latest weather information. Thus, such weather applications can be built using the Visual Crossing Weather API. Users can use such applications to stay updated about the weather and plan their activities accordingly.
News applications – The weather is also a vital component of news, so most news websites include weather information. Thus, the Visual Crossing Weather API can be used to embed weather information within news websites. Providing weather data in addition to news can help such websites to increase their coverage.
Travel applications – Finally, the weather plays a crucial role while planning vacations. So, travel websites can use the Visual Crossing Weather API to provide weather information to their end-users. Providing weather information can help users to travel websites to plan their vacation accordingly.
The Visual Crossing Weather API is a REST API. In brief, REST is a client-server architecture pattern. A REST service exposes some data on a server that can be retrieved by a client application and used as desired. REST services expose data in the form of HTTP URLs which are also known as REST endpoints. Most REST endpoints accept some input values (also known as REST parameters). They return an HTTP status code (indicating if the request was processed successfully or not) and optionally data corresponding to the request. The data is typically sent in JSON, XML, and CSV format. In addition, A REST endpoint can also be secured via authentication headers. Thus, a client application needs to send authentication information that is validated by the REST service and if valid, the request is processed.
The Visual Crossing Weather API works on the same principles. It exposes several endpoints that provide historical weather data as well as weather forecasts. An application can query an endpoint by supplying its URL, authentication headers (API key and API host provided by RapidAPI), and request parameters. The Visual Crossing Weather API then returns the requested information data.
You can use the Visual Crossing Weather API via RapidAPI. RapidAPI not only lists the API endpoints but allows executing an endpoint and viewing its results. This feature makes it very easy for developers to understand an endpoint’s response without writing any code. Not only that, RapidAPI provides code snippets that can be used to invoke the API endpoints in various programming languages. Thus, developers can get started with the API with minimal effort.
To use RapidAPI to connect to the Visual Crossing Weather API, you need to follow the steps given below.
The first step is to create a RapidAPI account as described below.
a. Enter the Visual Crossing Weather API RapidAPI URL (https://rapidapi.com/visual-crossing-corporation-visual-crossing-corporation-default/api/visual-crossing-weather/ ) in a browser. Click on the Log In/Sign Up button in the top right corner. This redirects to the following authentication page:
b. Authenticate yourself using any of the methods shown on the page like Google, Github, Facebook, or via email. Upon successful authentication, the following page is displayed:
The next step is to subscribe to the API. Subscribing to the API allows executing the API endpoints. The Visual Crossing Weather API has both free as well as paid plans. You can subscribe to a plan that is appropriate for you.
To subscribe to the Visual Crossing Weather API, you need to do the following:
a. Click on the Pricing Tab. This displays the following screen:
b. Select the desired plan. I have selected the Basic (Free) plan which allows 500 requests per month. This displays the following screen:
As explained earlier, RapidAPI allows executing an endpoint and viewing the response within the browser itself.
To execute an endpoint, you need to do the following:
a. Click on the EndPoints tab. All the available endpoints are displayed on the left:
b. Click the endpoint that you would like to execute. I have selected the Historical weather report endpoint. Click the Test Endpoint button:
c. View the Response in the Results tab:
Finally, RapidAPI provides code snippets in most of the popular programming languages which can be used to execute the API endpoints. Further, for each programming language, it provides code in multiple HTTP clients supported by the language (Since a REST API exposes its endpoints as HTTP URLs, a programming language specific HTTP client needs to be used to invoke an API endpoint). Thus, developers can obtain code for their desired programming language and desired HTTP client from RapidAPI without having to write code from scratch.
For example, to obtain a code snippet in C# using the RestSharp HTTP client, you need to do the following:
a. Click on C# -> RestSharp in the Code Snippets tab:
b. Copy the C# code shown and use it as desired:
Let us now take a detailed look at the Visual Crossing Weather API endpoints.
The Historical Weather Record endpoint returns the historical weather information for a given period of time and a given location. It accepts the following parameters:
The response consists of various weather-related fields like minimum temperature, maximum temperature, heat index, wind speed, and much more. For example, the endpoint returns the following response for location=Washington DC, startDateTime=2019-01-01, endDateTime=2019-01-03, aggregateHours=24 and contentType=json:
The weather forecast data endpoint returns the weather forecast for the specified location. It accepts the following parameters:
The response is quite similar to the Historical Weather Data endpoint and consists of various weather-related fields like minimum temperature, maximum temperature, heat index, wind speed, and much more. For example, the endpoint returns the following response for location=Washington DC, aggregateHours=24 and contentType=json:
As explained earlier, RapidAPI provides code snippets in various programming languages like Java, Python, PHP, Ruby, Javascript, NodeJS which can be used to execute the API endpoints. Let us take a look at a few code samples.
In order to use the Visual Crossing Weather API with Java, click the desired API endpoint on the left. In the code snippets tab, select Java and the desired HTTP client. Copy the code snippet and use it as required.
For example, RapidAPI provides the following Java code for the Historical Weather Report endpoint using the AsyncHttp client:
AsyncHttpClient client = new DefaultAsyncHttpClient(); client.prepare("GET", "https://visual-crossing-weather.p.rapidapi.com/history?startDateTime=2019-01-01T00%3A00%3A00&aggregateHours=24&location=Washington%2CDC%2CUSA&endDateTime=2019-01-03T00%3A00%3A00&unitGroup=us&dayStartTime=8%3A00%3A00&contentType=json&dayEndTime=17%3A00%3A00&shortColumnNames=0") .setHeader("x-rapidapi-key", "<your key here>") .setHeader("x-rapidapi-host", "<your host here>") .execute() .toCompletableFuture() .thenAccept(System.out::println) .join(); client.close();
In order to use the Visual Crossing Weather API with Python, click the desired API endpoint on the left. In the code snippets tab, select Python and the desired HTTP client. Copy the code snippet and use it as required.
For example, RapidAPI provides the following Python code for the Historical Weather Report endpoint using the Requests client:
import requests url = "https://visual-crossing-weather.p.rapidapi.com/history" querystring = {"startDateTime":"2019-01-01T00:00:00","aggregateHours":"24","location":"Washington,DC,USA","endDateTime":"2019-01-03T00:00:00","unitGroup":"us","dayStartTime":"8:00:00","contentType":"json","dayEndTime":"17:00:00","shortColumnNames":"0"} headers = { 'x-rapidapi-key': "<your key here>", 'x-rapidapi-host': "<your host here>" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
In order to use the Visual Crossing Weather API with PHP, click the desired API endpoint on the left. In the code snippets tab, select PHP and the desired HTTP client. Copy the code snippet and use it as required.
For example, RapidAPI provides the following PHP code for the Historical Weather Report endpoint using the HTTP v1 client:
<?php $request = new HttpRequest(); $request->setUrl('https://visual-crossing-weather.p.rapidapi.com/history'); $request->setMethod(HTTP_METH_GET); $request->setQueryData([ 'startDateTime' => '2019-01-01T00:00:00', 'aggregateHours' => '24', 'location' => 'Washington,DC,USA', 'endDateTime' => '2019-01-03T00:00:00', 'unitGroup' => 'us', 'dayStartTime' => '8:00:00', 'contentType' => 'json', 'dayEndTime' => '17:00:00', 'shortColumnNames' => '0' ]); $request->setHeaders([ 'x-rapidapi-key' => '<your key here>', 'x-rapidapi-host' => '<your host here>' ]); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; }
In order to use the Visual Crossing Weather API with Ruby, click the desired API endpoint on the left. In the code snippets tab, select Ruby and the desired HTTP client. Copy the code snippet and use it as required.
For example, RapidAPI provides the following Ruby code for the Historical Weather Report endpoint using the net::http client:
require 'uri' require 'net/http' require 'openssl' url = URI("https://visual-crossing-weather.p.rapidapi.com/history?startDateTime=2019-01-01T00%3A00%3A00&aggregateHours=24&location=Washington%2CDC%2CUSA&endDateTime=2019-01-03T00%3A00%3A00&unitGroup=us&dayStartTime=8%3A00%3A00&contentType=json&dayEndTime=17%3A00%3A00&shortColumnNames=0") 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"] = '<your key here>' request["x-rapidapi-host"] = '<your host here>' response = http.request(request) puts response.read_body
In order to use the Visual Crossing Weather API with Javascript, click the desired API endpoint on the left. In the code snippets tab, select Javascript and the desired HTTP client. Copy the code snippet and use it as required.
For example, RapidAPI provides the following Javascript code for the Historical Weather Report endpoint using the Axios client:
import axios from "axios"; const options = { method: 'GET', url: 'https://visual-crossing-weather.p.rapidapi.com/history', params: { startDateTime: '2019-01-01T00:00:00', aggregateHours: '24', location: 'Washington,DC,USA', endDateTime: '2019-01-03T00:00:00', unitGroup: 'us', dayStartTime: '8:00:00', contentType: 'json', dayEndTime: '17:00:00', shortColumnNames: '0' }, headers: { 'x-rapidapi-key': '<your key here>', 'x-rapidapi-host': '<your host here>' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); });
In addition, RapidAPI can also be used to obtain code snippets in many other programming languages like Node.js, C, Kotlin, Swift, etc.
Well-documented – The most important benefit of the Visual Crossing Weather API is that it is well-documented. The API endpoints include descriptions that explain what the endpoint does. Further, the parameters to each endpoint also include descriptions, sample values, and default values as appropriate. This enables developers to understand and use the API without a steep learning curve.
Cost-effective – Another important benefit of the Visual Crossing Weather API is that is it cost-effective. It has a free plan that offers 500 requests per month. Moreover, the Pro plan costs only $10 per month and offers 10000 requests per month. Thus, the API is a good option for developers looking for an economical weather API.
Minimalistic – Finally, the Visual Crossing Weather API is minimalistic. It provides only two endpoints that provide the historical weather information and weather forecast. Thus, developers that are only looking for these basic features can use the API without having to browse through tons of API methods.
Just like the Visual Crossing Weather API, there are many other APIs available on RapidAPI that provide weather information. Some of these are as follows:
1. AccuWeather API – The AccuWeather API is a comprehensive weather API. It includes a large number of endpoints that provide daily and hourly weather forecasts, weather conditions for top cities, and much more.
2. Weather API – The Weather API is another weather API that provides the current weather data. It provides a 16-day, 5-Day, and 120-hours forecast. It even provides hourly and minutely forecasts.
3. Air Quality API – The Air Quality API provides current, forecasted, and historical air quality for any point in the world.
4. AerisWeather API – The AerisWeather API is an advanced weather API. It provides information about weather alerts issued to the public by the US/Canadian Government, weather forecasts, current sun/moon information, and much more.
5. Yahoo Weather API – The Yahoo Weather API is another weather API. It provides weather information by location and geolocation.
Summary
So, to summarize, The Visual Crossing Weather API is a weather-related REST API. It exposes endpoints that provide historical weather data as well as weather forecasts. In this article, we saw how to connect to the Visual Crossing Weather API using RapidAPI. We also took a look at all the API endpoints, the benefits of the API, and other alternative APIs that provide weather-related data. Finally, we saw how to write code that invokes the endpoints in various programming languages.
We're thrilled to announce the latest update to the Rapid Enterprise API Hub (version 2024.3)!…
Are you curious about what your API consumers are searching for? Is your Hub effectively…
The RapidAPI team is excited to announce the February 2024 update (version 2024.2) for the…
This January's release brings exciting features and improvements designed to empower you and your developers.…
Rapid API is committed to providing its users with the best possible experience, and the…
In today's fast-paced digital world, APIs (Application Programming Interfaces) have become the backbone of modern…