WeatherStack API: Real-time Weather Data for Your Project
If you need to add weather information to your website or to an app you’re developing, the first thing you need is a reliable source of weather data. But that’s not all, you also need a method of fetching that data. Wouldn’t it be great if there was a tool that allowed you to easily fetch various types of weather data and include it in your app or site? Well, there is. It is called the Weatherstack API and it was built to do just that. Today, we’re having an in-depth look at this API, what it can do for you and how you can put it to use.
About Weather Data
As defined by Wikipedia, “Meteorology is a branch of the atmospheric sciences which includes atmospheric chemistry and atmospheric physics, with a major focus on weather forecasting.” And while there is more than weather forecasting to that science, it is its main branch. For as long as we’ve been, we’ve always wanted—and often needed—to predict what the weather was going to be like. Throughout the centuries this science—like all others—has considerably evolved up to relatively precise science it now is. Of course, weather forecasting is an error-prone field and we’ve all gotten caught by an unexpected shower at one point or another.
Today, several national agencies or private organizations provide weather forecasting and observation services that cover pretty much the whole globe. And while the exact information each group provides and how it is formatted can vary, the tends to be more and more uniform, making it easier for international organizations to get similar data about different locations.
Adding Weather Data To You Site Or App
There are many reasons why one would want to incorporate weather data in their app or their website. The most basic reason would be for someone building a weather app or site. And using a tool such as the Weatherstack API, one can easily fetch weather data for almost any location on the globe and present it in any way they want. All you have to do is determine what information you want to present to your users and how you want to present it. Two different applications or websites could be fetching the same data from Weatherstack yet present it in a completely different way.
But building weather apps of sites is not the only use for weather data. Imagine you run a nice bed and breakfast by the sea coast. Wouldn’t it be nice if you could include the current weather and forecast right there on your home page? Well, a weather data provider such as Weatherstack will let you do just that. Even better, it will do it automatically for you. All you need is add the appropriate code to your site and voilà! You have the weather forecast right on your site.
We could easily think of a bevy of similar uses to anyone wishing to add any kind of weather data to its app or site. If you, for instance, run any kind of outdoor operation, you may want to supply your clients with some current weather data or an upcoming forecast.
We could go on forever with good examples of using weather data either on your website on an application. The truth is that the only limit to what can be done with it is only one’s imagination. I’ve seen sites that had nothing to do with the weather but still included some weather data.
A First Look At The Weatherstack API
The Weatherstack API is actually rather simple. It’s a web-based service that you can use to fetch weather data about almost any location. Once you have the data, what you do with it is entirely up to you. What the API provides is just a source of live and up-to-date international weather data. The tool is super simple to use and it’s pricing model makes it easy to pay for just what you need.
The Weatherstack API delivers both real-time, historical, and future (forecast) weather information. Its primary target clientele is big and small organizations, as well as developers, freelancers and individuals. It is one of the most popular weather data REST API providers on the market due to its ease of implementation and data consistency.
Weatherstack is a service by Apilayer, a software company based in London, United Kingdom and Vienna, Austria. It is behind some of the most popular API and SaaS products worldwide. Those include things like Ipstack, Currencylayer, Invoicely, and Eversign. The API is using licensed weather data from some of the largest weather stations and weather data providers in the world. Furthermore, all the data sources are closely monitored for consistency and data accuracy around the clock. You always get the highest level of reliability, consistency and accuracy.
Although the refreshing frequency of weather data differs from one source to another, all data returned by the Weatherstack API—current, past, and future—is always the most up-to-date information available at the current point in time. Weather data is always updated in real-time. You can use it with confidence and trust that it is the most current data available.
It is one thing to have current data but it is also important to be able to fetch that data whenever you need it. And on that front, the Weatherstack API leaves nothing to be desired. It has a stellar uptime record and although the company advertises a 99.9% uptime, recent statistics show that the service hasn’t been down once in the past thirty days. But it’s not only available, but it also performs well. All weather data is returned in JSON format which makes for a fast response. The query response time is rarely above half a second and usually much shorter. Of course, your experience may vary and various issues outside of the provider’s control could slow down the process.
The Weatherstack API is also highly scalable. It is backed by a cloud infrastructure built and maintained by Apilayer which is capable of handling billions of requests per day. And if security is important to you—as it most likely is—the queries and responses can be secured using industry-standard 256-bit HTTPS (SSL) encryption. This is the same level of encryption that you get on banking websites.
And since any product—and especially an API—is only as good as its documentation, you’ll appreciate the thorough documentation provided with the Weatherstack API. You’ll find easy to understand document for pretty much every possible use case. Furthermore, a series of interactive code examples in multiple languages are provided. In many cases, using the API will be a simple matter of copying code from the examples into your own application. It could hardly be easier.
The Weatherstack API’s Main Features
The feature set of the Weatherstack API is impressive. It varies depending on the plan you choose and, of course, the price you pay. (More about pricing below). Let’s have a deeper look at what is actually available in terms of features.
Real-Time Weather is the Weatherstack API’s most basic feature and the only one that is included in all plans, even the free one. What it gives you is instant access to current weather data for millions of global locations. It is, of course, powered by rock-solid data sources and refreshed in real-time.
The Location Lookup & Autocomplete module is only available with paid plans. It provides a flexible search & autocomplete API endpoint that can help you easily pinpoint any city or region of your choice. You can search by name, by ZIP code, by geographical coordinates or even by IP address. That last feature can be very handy if you want to include localized weather data to your site’s visitors. It uses geolocation techniques to find the physical location of your visitors based on their IP address.
The Astronomy & Lunar Data module—available on all paid plans—lets the Weatherstack API deliver a series of valuable astronomy data points. These include information such as the sun and moon rise and set times, the moon phase and the moon illumination levels.
The Weatherstack API also delivers Hour-by-Hour Data on all paid plans. You’ll get very accurate real-time and also historical weather data broken down to the hour for the past 24 hours including temperature, wind, humidity, rain and a lot more.
And if you want to get more ancient data, all paid plans include Historical Weather Data which lets you full and detailed historical weather information globally all the way back to the year 2008. This feature is included with all paid plans as well.
When it comes to weather, though, we are often more interested in what the future has in store for us rather than what the past was. This is where then Weather Forecast Data module comes in handy. It will provide a reliable weather forecast data for 7 to 14 days into the future (depending on your plan), updated in real-time and around the clock.
Not everyone speaks English and the makers of the Weatherstack API know that. This is why the API is available in 40 different languages with the Professional and Business plans. The available languages include English (of course), Chinese, Arabic, French, Spanish and German, just to name a few.
Now if you need to fetch lots of weather data, running multiple individual queries can be complicated, cumbersome and rather slow. Fortunately, the Weatherstack API comes with the Bulk API feature. Bulk queries let you look up real-time, historical or future weather data for multiple global locations in a single API request.
Using Weatherstack
Let’s have a look at how you can use the Weatherstack API. Our goal is not to provide you with an in-depth tutorial—the great documentation available on the Weathersrack API’s website can be used for that—but rather to give you an overview of how easy it is to use the service and what the returned data may look like.
Invoking the Weatherstack API is as simple as sending a get request to api.weatherstack.com. That URL is extended to specify the type of request. You would, therefore, use either api.weatherstack.com/current, api.weatherstack.com/historical or api.weatherstack/forecast, If you need encryption, simply prefix the call with https:// instead of https://.
You need, of course, to send a few parameters with your request. The first—and most important—one is your API key. This is a unique key that is assigned to you when you sing up for the service. Another required parameter is called “query’. It is the actual query you want to run. That is the location for which you want to retrieve data. It could be a single location such as “London, United Kingdom” but it could also be multiple locations separated by semicolons like “London, Madrid, New York” The search engine is smart enough that you don’t need to enter more than just the city name for most well-known locations. That is unless, of course, you need something specific such as the weather in London, Ontario, Canada.
There are also a handful of optional parameters that enable users to specify parameters such as the number of days to forecast, the measurement units, of the language. And since the response is in JSON format, you can also specify a JSONP callback function that will handle the response. This is very powerful.
Once you sent your request, here’s an overview of the response you’re going to get:
{ "request": { "type": "City", "query": "New York, United States of America", "language": "en", "unit": "m" }, "location": { "name": "New York", "country": "United States of America", "region": "New York", "lat": "40.714", "lon": "-74.006", "timezone_id": "America/New_York", "localtime": "2019-09-07 11:38", "localtime_epoch": 1567856280, "utc_offset": "-4.0" }, "current": { "observation_time": "03:38 PM", "temperature": 18, "weather_code": 113, "weather_icons": [ "https://assets.weatherstack.com/images/wsymbols01_png_64/wsymbol_0001_sunny.png" ], "weather_descriptions": [ "Sunny" ], "wind_speed": 0, "wind_degree": 345, "wind_dir": "NNW", "pressure": 1011, "precip": 0, "humidity": 58, "cloudcover": 0, "feelslike": 18, "uv_index": 5, "visibility": 16 }, "forecast": { "2019-09-07": { "date": "2019-09-07", "date_epoch": 1567814400, "astro": { "sunrise": "06:28 AM", "sunset": "07:19 PM", "moonrise": "03:33 PM", "moonset": "12:17 AM", "moon_phase": "First Quarter", "moon_illumination": 54 }, "mintemp": 17, "maxtemp": 25, "avgtemp": 21, "totalsnow": 0, "sunhour": 10.3, "uv_index": 5, "hourly": [ { "time": "0", "temperature": 18, "wind_speed": 28, "wind_degree": 15, "wind_dir": "NNE", "weather_code": 122, "weather_icons": [ "https://assets.weatherstack.com/images/wsymbols01_png_64/wsymbol_0004_black_low_cloud.png" ], "weather_descriptions": [ "Overcast" ], "precip": 0, "humidity": 68, "visibility": 10, "pressure": 1008, "cloudcover": 75, "heatindex": 18, "dewpoint": 12, "windchill": 18, "windgust": 35, "feelslike": 18, "chanceofrain": 0, "chanceofremdry": 87, "chanceofwindy": 0, "chanceofovercast": 90, "chanceofsunshine": 15, "chanceoffrost": 0, "chanceofhightemp": 0, "chanceoffog": 0, "chanceofsnow": 0, "chanceofthunder": 0, "uv_index": 0 }, { "time": 300, ... }, { "time": 600, ... }, // 6 more items ] } } }
As you can see, that’s a lot of information. You get complete current weather data such as temperature, wind direction and speed, humidity, barometric pressure, and UV index, among others. The forecast section is just as detailed and includes, for instance, the chance of precipitation in percentage, heat index, wind chill factor, and dew point. One last thing worth noting is that the response also includes URLs to icons you can use to add visual interest to your weather data.
We could spend quite a bit of time going over all the options and the various bits of data included in the query responses. However, since the Weatherstack API website has such detailed documentation, we figured it was not necessary. And if you need concrete examples of how to use the Weatherstack API with your programming language of choice the online documentation has several code examples in PHP, Python, Nodejs, jQuery, Go and Ruby.
Pricing Information
The Weatherstack API is available under several different plans. As we saw, the plans vary in the number of features they each offer but they also vary in the maximum number of API calls you can make each month.
The most basic plan is the Free plan. It costs nothing and a credit card is not even required to sign up for that plan. It is, however, severely limited in that it will only allow up to a thousand API calls per month. Its primary use is for testing purposes.
Next up is the Standard plan with many more features—it’s only missing the forecast module and the multiple languages—and a monthly allocation of up to fifty thousand calls. This plan is available for $9.99/month or $7.99/month if you pay annually.
The mid-range plan—and also the most popular—is the Professional plan. At this level, you get the full feature set and multilingual support as well as an extended allocation of up to three hundred thousand call per month. This one is priced at $49.99 or $39.99 if billed yearly.
The top plan—called the Business plan—offers the same full feature set as the professional one but in increases to monthly allocation to one million calls per month. It is, of course, the priciest plan at $99.99/month or $79.99 with yearly payments.
And if none of these plans seem to match your needs, you can contact Apilayer and arrange for a customized Enterprise plan. It will include the features you need and the monthly allocation you require. This level also features dedicated support as well as the possibility of custom solutions which fit your specific needs.
Bottom Line
If you need to add weather data to a website or an app you’re developing, the Weatherstack API can provide you with precisely what you need at a very reasonable price. The product is easy to use and it will easily integrate into your existing environment. The service is fast and efficient, its availability is stellar and its quality second to none. With an available free plan, try it and see for yourself how this tool can help you achieve your goals.