Example: DataSource.Get

DataSource.Get uses the Get Utility to retrieve data, even cross-domain resources, via a dynamically created script node. A DataSchema plugin is used to normalize incoming data into a known format for consistency of usage by other components. Please note that your data resource must support a callback mechanism, which is a function wrapper around the returned data. The name of the callback function is passed to the resource via a query string parameter defined by the DataSource.Get attribute scriptCallbackParam.

JSON

Data
{
    "query": {
        "count": 51,
        "created": "2013-06-04T22:50:08Z",
        "lang": "en-US",
        "results": {
            "place": [
                {
                    "lang": "en-US",
                    "uri": "http://where.yahooapis.com/v1/place/2347575",
                    "woeid": "2347575",
                    "placeTypeName": {
                        "code": "8",
                        "content": "State"
                    },
                    "name": "Kansas"
                },
                {
                    "lang": "en-US",
                    "uri": "http://where.yahooapis.com/v1/place/2347595",
                    "woeid": "2347595",
                    "placeTypeName": {
                        "code": "8",
                        "content": "State"
                    },
                    "name": "Oklahoma"
                },
                {
                    "lang": "en-US",
                    "uri": "http://where.yahooapis.com/v1/place/2347584",
                    "woeid": "2347584",
                    "placeTypeName": {
                        "code": "8",
                        "content": "State"
                    },
                    "name": "Missouri"
                },
                ...
            ]
        }
    }
}
    
Schema
{
    resultListLocator: "query.results.place",
    resultFields: ["name"]
}
    
Normalized data

Use a DataSourceJSONSchema plugin to parse the data against a schema that you provide:

YUI().use("datasource-get", "datasource-jsonschema", function(Y) {
    var myDataSource = new Y.DataSource.Get({
            source: "http://query.yahooapis.com/v1/public/yql?format=json&"
        });

    myDataSource.plug(Y.Plugin.DataSourceJSONSchema, {
        schema: {
            resultListLocator: "query.results.result",
            resultFields: ["title"]
        }
    });

    myDataSource.sendRequest({
        request: 'q=select * from geo.states where place="United States"',
        callback: {
            success: function (e) { /* output to screen */ },
            failure: function (e) { /* output to screen */ }
        }
    });

});