APIs are inherently difficult to learn for developers. The ProgrammableWeb API is no exception to this rule either. In this article we will show some examples of how Yahoo’s YQL can be used make developer’s life a bit easier when using the ProgrammableWeb API.
The main difficulty with APIs in general is that they require the developer to create and remember a number of cryptic URLs via which certain data can be retrieved from the API. Another issue is, that often fairly simple data requests need to be expressed in multiple API calls, which then have to be merged by the developer itself in order to further use this data in his application.
So what can be done to overcome this misery? Yahoo’s YQL tries to address this by converting API calls into SQL-like commands, which are somewhat more human readable. Let’s look at a couple of examples of how YQL can be used to interact with the ProgrammableWeb API.
To show the mashups that are using a certain API, you need to send this call to the ProgrammableWeb API:
In YQL, you get the same data with this call:
SELECT * FROM pw.mashups
WHERE apis=“google-maps” AND apikey=“YOUR_API_KEY”
While this is not shorter than the bare API call, it tells you a bit more about what you are requesting and from where. Lets have a look at another example.
To find ProgrammableWeb members from San Francisco, you need this API call:
Expressed in YQL this is:
SELECT * FROM pw.members
WHERE query=“San Francisco” AND apikey=“YOUR_API_KEY”
This YQL query is very similar to the one in example 1, with just one minor twist. When defining the YQL table for an API, YQL allows for renaming of parameters in order to improve the readability of the API calls. In this case I have renamed the q parameter to query, to show this.
YQL shines even more in areas where it can provide an abstraction layer to simplify queries in the original API. For example, in order to retrieve the member data of 3 different ProgrammableWeb members (usernames: jmusser, duvander, spier) you have to issue 3 API calls:
With YQL you can do all in one call:
SELECT * FROM pw.members
WHERE (username="jmusser" OR username="duvander" OR username="spier")
Hopefully but now I got you a bit excited about YQL and the ProgrammableWeb API, and you want to try it out.
I have created an initial set of YQL tables for the ProgrammableWeb API, which can be found in this github repository. These YQL tables are not complete yet, meaning they do not cover all API calls but it is a good start. In order to try out the YQL calls in this article, you need to do this:
Have fun while trying this out, and post comments about your experience with YQL and the ProgrammableWeb API below. Looking forward to hear from you.