Web API power tools: One tool to bind them all
That approach works well, but there is one major problem: It requires you to learn a new API for each RESTful service you want to try out.
Wouldn’t it be nice if there was one mechanism you could learn that allowed you to make calls into just about any web API, or even plain old web pages? In fact there is, and that’s the subject of this post: the Yahoo! Query Language (YQL).
I first wrote about YQL for the PayPal X Developer Network in a two part DevZone article series on harvesting and analyzing RSS feed data (click here to read the first part on harvesting the data; the second part will be publishing soon). You can read more about YQL in detail in those articles, so for this post I just want to cover the high level capability to show you its usefulness in your web API-based development.
So what is YQL? YQL looks like SQL but enables you to access live data from the Internet. That definition doesn’t really do it justice, however.
The bigger point about YQL is that it includes many built-in bindings to various web APIs so that you can use almost every major web API in a consistent manner, with similar calls across the many possible APIs available to you. Yahooligans summarize this capability as:
select * from Internet
Here’s why. In the first article in my harvest+analysis series I showed how you could use YQL to load DevZone “Blog” RSS feed data:
select * from rss where url in ('https://www.x.com/community/feeds/blogs?community=2133')
In the second part of the series you see how you can use that same YQL in an application. The article shows a Python example using the Python YQL client library, but you can use it in other languages too with the appropriate library. Barring direct support in a particular language of interest, however, you can always make the equivalent REST call provided for any given YQL statement you put together in the YQL console.
For instance, if you enter the above YQL into the console and test it with diagnostic information turned off and the server response set to ‘XML’ (JSON is the other option), the console gives you this output:
In this case, the REST query copied out of the highlighted portion of the console is:
Click the REST query above to see the server response live in your browser. You can use this REST call in your application code, no matter the programming language or environment. Nifty, huh?
But what if you want to use that same DevZone data, or data from a different RSS feed or server, in an application where you also need access to other web APIs? No problem, YQL supports many other web API queries too. It does this via Open Data Tables created with just a little bit of XML. Click here to learn more about the data tables.
For example, suppose you want to search Twitter for tweets containing “PayPal”.
Read the complete post on the PayPal X Developer Network to learn how to use the Twitter search API in YQL.