Next in our series of the “Hello World of APIs” we are looking at Yahoo WeatherTrack this API, a very popular API that provides the latest weather information. As with our previous tutorials, we will focus on detailing what a developer needs to know in order to understand the API and build an application that integrates with it.
- Understanding the API – API types, security, etc.;
- Sending the request – Walkthrough of our example application;
Understanding the API
Yahoo provides information on the Weather API at the Yahoo Developer Network (YDN) site. The core documentation is freely available to read without a Yahoo account, but a developer must register for a YDN account if they call a Yahoo API that requires the use of a client ID and secret.
Yahoo organizes information on the Weather API into the following sections:
- Get Started
- Create An App
We’ll cover each of these in turn.
The Get Started page provides the developer with a simple overview of what they need to the do to start developing against the Weather API. This includes the following:
- A link to the Create an App page that allows a developer to get the Client ID and Secret required to access the API. Note that in the case of the Weather API this is not required for personal, non-commercial use, but an Application ID is required to access the Yahoo GeoPlanet API, which, in some cases the RSS version of the Weather API relies on (more on this below).
- A link to the YDN forums.
The documentation page covers only the format of the RSS version of the Weather API, including the required query parameters and the response structure. As mentioned above, you’ll also need to read the GeoPlanet API documentation in order to understand how to retrieve a WOEID (Where On Earth ID) that the RSS version relies on for looking up the weather for a given place.
However, developers have the option of using YQL, and given that the code snippets mentioned above were created using YQL this appears to be Yahoo’s preferred version of the API. In order to use the YQL interface developers should refer to the main YQL page instead. You can also use the YQL console to help you create YQL queries that you can use in your Weather API calls, making queries against the weather.forecast table. There is no API description specification so understanding the API relies on using examples in the console to elicit an understanding of the responses.
Create An App
Yahoo requires a developer to create an app for some of their APIs which is essentially a logical entity registered to their Yahoo user account and used as an internal identifier for the application accessing the API. As mentioned above, creating an app is not required to access the RSS version of the Weather API per se, but developers will need to access the GeoPlanet API to look up the WOEID so using this feature is required. Once you’ve created an app you’ll have access to the app overview page that contains the application ID you need to access the GeoPlanet API, as shown below. However, if you use the YQL interface to query the Weather API you do not need to create an app. YQL queries can be performed without an authentication.