running a WebDav GET request against YQL

This builds off my previous post. Suppose you’ve got content in YQL that you’d like to GET (ha!) out. The table is super simple.  Ok, this is really just an unexciting GET request to YQL, but it’s cool because we’re starting to think of YQL as a file store accessible via WebDAV methods.


  • A sherpa record w/ this value in it: {“file1″:”content 1”, “file2”, “content 2”}.  The keys and values w/in the JSON can be anything.  If you haven’t worked w/ YQL storage before, check out the documentation.
  • The code below edited to use your storage record’s select address


  1. You make a GET request to YQL w/ a query param path set the the value of one of your keys in the JSON object described above, eg path=’file1′
  2. YQL retrieves the storage record, converts it to JSON, and returns the value associated w/ the path you sent


<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="">
        <author>Erik Eldridge</author>
        <select produces="XML">
                <key id="path" type="xs:string" paramType="variable"/>
                response.object = function () {

                    //fetch 'files'
                    var query = 'select * from where name="store://{select store id}"',
                        results = y.xmlToJson(y.query(query).results);

                    return results.results.result.value[path];


  • If you wanted to use a WebDAV client w/ this output, you could run something like this Ruby code in a Rack app, and point your WebDAV client at it:
    file = 'file1'
    query = "use '' as table; select * from table where path='#{file}'"
    host = ''
    path = '/v1/public/yql'
    q = Rack::Utils.escape(query)
    # setting debug to true turns off YQL's caching, which is good when testing
    uri = "#{host}#{path}?q=#{q}&debug=true"
    res = Net::HTTP.get_response( URI.parse(uri) )
    doc =
    # extract the 'results' element
    result = REXML::XPath.first( doc, "//results" )
    # return the flattened xml
    [200, {"Content-Type" => "application/xml"}, '<?xml version="1.0" encoding="utf-8"?>' + result.elements[1].to_s]

One thought on “running a WebDav GET request against YQL

Comments are closed.