Accessing Cross Domain Data with YQL

date:2011-04-10 14:14
category:javascript, OpenLayers
tags:geoext, yahoo, yql

imageThe same origin policy prevents code from one domain accessing data from a different domain. For a mapping site requests for KML, GeoRSS, WFS services, and some WMS operations are all affected by this policy, and therefore require a range of workarounds, usually involving a proxy.

One solution is the ExtJS ScriptTagProxy that can be used to retrieve data from an external domain. However for this to work the server must return executable JavaScript code. For example to access an external WMS capabilities file you’d need to set up a special handler on your server to wrap the data in JavaScript before being added to your web page. This pattern is referred to as JSONP (JSON with padding).


Thanks to this Unwritten Guide to Yahoo Query Language it became apparent you can get Yahoo to automatically do this wrapping for you. Whilst using YQL is still technically a proxy, it’s a proxy you don’t have to worry about maintaining.

I’m not a huge fan of relying on commercial APIs and services, partly as if they are free then they can also change without warning or disappear, and partly as fully understanding the Terms of Service requires both a law and computer science degree.

However configuring your own proxy and wrapping is a large overhead if accessing data from another domain is the only reason you need server-side code.

YQL looks a lot like standard SQL, but can be used to query data from a URL. Go to the YQL Console and try out the following query:

select * from xml where url=''

An External WMS Capabilities Store

This method can be used to easily access a WMS Capabilities file on an external server. I’ve put a small demo online showing a working example. The source code can be found on BitBucket.

The example is based on GeoExt’s original WMS Capabilities demo. The code makes use of the ScriptTagProxy, and a slightly modified reader that takes the results part of the JSON (the XML) and passes it on to the standard WMSCapabilitiesReader: = Ext.extend(, {
    readRecords: function(data){
        data = data.results.toString();
        return, data);

Yahoo have many “clones” of services offered by the other web giants, which whilst well implemented don’t really interest me - when was the last time you looked at Yahoo Maps?. However along with YQL, Yahoo have a few interesting and unique developer tools such as Yahoo Pipes and YUI (in fact ExtJS branched out of YUI), so its worth keeping an eye on the often forgotten man of the Internet.



1. Samuel Smith **

Hey Man,

I’m super close getting this proxy to work ... I seems to be exactly what I need, but am getting a 401.3 (Access Denied) error.

I’ve given ASPNET and NETWORK service full control on the directory (all files/subs), and IUSR_ read, write, execute, restarted the app pool (and IIS) ...

Have you come across this issue or got any other directions? Please :) Am in IIS 6 on 32 bit Win Server 2003.

Add Comment