logo

Yahoo Query Language

Not sure how YQL (Yahoo Query Language) has escaped my attention for so long, as it seems so useful.

YQL lets you query any of the Yahoo's APIs using a SQL-like syntax. For me this came in handy when I wanted to create a simple stock-tracking mobile app.

In JavaScript I could get the stock quote for Google's stock as JSON, like so:

function getStock(symbol){
  var YQL="select * from yahoo.finance.quotes where symbol ='"+symbol+"'";
  var URL="http://query.yahooapis.com/v1/public/yql?q=" + escape(YQL) + "&format=json";

  //Do an AJAX call to the above URL to get the JSON back.
}

To see what the JSON look like see it on the console.

When it comes to using it in mobile apps, if you use Titanium then you can use the YQL wrapper and write code like this:

Titanium.Yahoo.yql(
 "select * from yahoo.finance.quotes where symbol = 'GOOG'", 
 function(e) {  
  var data = e.data;
  //Do what you like with the data JSON object
 }
);

All very useful.

Comments

  1. Yep -- pretty cool, the services they have available. Used them when I did a bit of webOS development for fun that used Yahoo's YQL quite a bit -- webOS made developing apps like that really easy. Makes me wish, sometimes, that I could do an ajax command for an external website in a web browser. :P

    Only sometimes.

    1. I'm not sure what you meant by "ajax command for an external website". But if you want to get data from other sites with Ajax, you actually can do it. Have you looked into JSONP (JSON with padding)?

      If the other site doesn't provide it's services in the JSON format, you can use Yahoo Pipes module Fetch Page to act as a proxy. Then you just grab the output of your pipe in JSON(P).

    • avatar
    • Paul
    • Thu 23 Jun 2011 03:42 AM

    Jake, also worth a look is yahoo pipes - pipes.yahoo.com .

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Wed 22 Jun 2011

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content