What is YQL

modified from http://www.wait-till-i.com/tag/introduction/

YQL stands for Yahoo! Query Language and is a way to easily get information from web services like Yahoo News! Twitter Feeds and Google services and inlcude them in an application (widget) you want to create for the web/your web site.

 

What is YQL and what is it good for ?

The Web is composed of the presentation and exchange of information. Think aobut Facebook - and status lines, twitter feeds, Yahoo! News and much more.

This information comes in different formats. For example, the photos on http://www.flickr.com/photos/tags/cat are available in “JSON” format at http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&lang=en-us&format=json.

Unfortunately each company has it s own way of code this information / formatting it. What YQL helps developers to do is to leverage work on accepting different formats from different web services and gives a standard way of accessing and recieving the data. This can allow you to create mashups - the mixing of different information sources inside of an application you create for a different purpose or presentation.

You can for example map the news onto the world to give them geographical context.

In normal communication amongst people with different languages we have translators – sometimes even simultaneous ones. And this is what YQL is. YQL is a simple to understand language to allow you to get information from any source on the web and gives it back to you in a language you understand. Every resource on the web can get a simple name and developers can call this name up to get to the data it offers.

 

YQL in Action

So for example getting photos from flickr using YQL becomes

select * from flickr.photos.search where text='cat'

Translating a text to French becomes using YQL:

select * from google.translate where q='hubcap' and target='fr'

You can also mix and match different sources, for example you can get the latest headlines from yahoo’s top stories and translate them to French:

select * from google.translate where target='fr' and q in (
select title from rss where url='http://rss.news.yahoo.com/rss/topstories'
)

YQL syntax based on SQL

This language is very close to another language called SQL which is the standard for accessing information in databases. So, in essence, YQL turns the internet into a massive database where developers can access information and remix it to make it easier for end users to see relationships between different pieces of information or even develop interfaces that make it possible for users to get access to the information.

For example this great lecture on YouTube can be listened to by blind users using the EasyYouTube interface that uses YQL to get to the information of the video.

YQL can be accessed on a pure programmatic level but the easiest way to get a glimpse of its translation and access powers is to use the console.

YQL is a great communicator – it allows you to speak to all kind of data sources in the right language, ask the right questions for you, find the right internal phone numbers to get to even other resources needed to get to a certain piece of information and give back to you only what you asked for and not a whole mass of information you will never need. And it is amazingly fast in doing so as Yahoo built it to deal with exactly the same problem of data communication inside the company.

 

YQL - how to use it

The following YQL statement, for example, retrieves a list of cat photos from Flickr:

SELECT * FROM flickr.photos.search WHERE text="cat"

To access the YQL Web Service, a Web application can call HTTP GET, passing the YQL statement as a URL parameter, for example:

http://query.yahooapis.com/v1/public/yql?q=SELECT * FROM flickr.photos.search WHERE text="Cat"

Here are the results of typing in the above URL in a browser....this is the 10 videos at that moment for cats on flicker:

<query yahoo:count="9" yahoo:created="2011-02-18T19:54:58Z" yahoo:lang="en-US">
-
<results>
<photo farm="6" id="5456857132" isfamily="0" isfriend="0" ispublic="1" owner="66972807@N00" secret="0158d7bdba" server="5131" title="Still Life With New Clock"/>
<photo farm="6" id="5456241213" isfamily="0" isfriend="0" ispublic="1" owner="47372746@N00" secret="2f1877fed0" server="5216" title="RIP Frodo: 1995 - 2011"/>
<photo farm="6" id="5456252599" isfamily="0" isfriend="0" ispublic="1" owner="20846638@N04" secret="5879cee952" server="5252" title="A Hairless Cat's Ear?"/>
<photo farm="6" id="5456251657" isfamily="0" isfriend="0" ispublic="1" owner="32276183@N00" secret="5343a104c2" server="5215" title="Clare and Dora"/>
<photo farm="6" id="5456246703" isfamily="0" isfriend="0" ispublic="1" owner="92349717@N00" secret="d482c055ae" server="5255" title="Just another lazy day... in my favorite sunny spot"/>
<photo farm="6" id="5456850878" isfamily="0" isfriend="0" ispublic="1" owner="32276183@N00" secret="c0b90c636b" server="5131" title="Clare and Dora"/>
<photo farm="6" id="5456252359" isfamily="0" isfriend="0" ispublic="1" owner="7604309@N06" secret="ca3e2af9a4" server="5134" title="Weird ass cats"/>
<photo farm="6" id="5456238607" isfamily="0" isfriend="0" ispublic="1" owner="78394733@N00" secret="c5ba2b11de" server="5298" title="Smoke"/>
<photo farm="6" id="5456235155" isfamily="0" isfriend="0" ispublic="1" owner="78394733@N00" secret="15a551e55e" server="5175" title="Smoke"/>
</results>
</query>

What now --- you need to know how to use this information from Flickr to bring up the actual images.

YQL - 2 output formats

currently will return either XML (as shown in previous example) or JSON as the returned data output from a YQL call.

 

YQL - Why use it?

Well, you could write directly to the web service api --but, why not leverage others work (and let them ..but, you are dependent...update it when the web service api changes).

Here are some reasons:

Why Use YQL?

The YQL Web Service offers the following benefits:

  • Because it resembles SQL, the syntax of YQL is already familiar to many developers. YQL hides the complexity of Web service APIs by presenting data as simple tables, rows, and columns.
  • YQL includes pre-defined tables for popular Yahoo! Web services such as Flickr, Social, MyBlogLog, and Search.
  • YQL can access services on the Internet that output data in the following formats: HTML, XML, JSON, RSS, Atom, and microformat.
  • YQL is extensible, allowing you to define Open Data Tables to access datasources other than Yahoo! Web Services. This feature enables you to mash up (combine) data from multiple Web services and APIs, exposing the data as a single YQL table.
  • You can choose either XML or JSON for the format of the results returned by requests to YQL.
  • YQL sub-selects enable you to join data from disparate datasources on the Web. YQL returns the data in a structured document, with elements that resemble rows in a table.
  • With YQL, you can filter the data returned with an expression that is similar to the WHERE clause of SQL.

 

YQL Examples and Resources (also see links)

EXAMPLE : Maping Yahoo! news on a Map using YQL

 

Videos:

© Lynne Grewe