YUI3 Gallery

YUI IO Utils

Utilities to make IO simpler to use

View on GitHub API Docs

Getting Started

To include the source files for YUI IO Utils and its dependencies, first load the YUI seed file if you haven't already loaded it.

<script src="http://yui.yahooapis.com/3.9.1/build/yui/yui-min.js"></script>

Next, create a new YUI instance for your application and populate it with the modules you need by specifying them as arguments to the YUI().use() method. YUI will automatically load any dependencies required by the modules you specify.

<script>
// Create a new YUI instance and populate it with the required modules.
YUI({
    gallery: 'gallery-2013.05.10-00-54'
}).use('gallery-io-utils', function (Y) {
    // YUI IO Utils is available and ready for use. Add implementation
    // code here.
});
</script>

For more information on creating YUI instances and on the use() method, see the documentation for the YUI Global Object.

Using promises for IO

All utility methods included in this module return a promise instead of taking callbacks or event listeners. Promises allow you to pass around a token to the future value of the response. When you are ready to use that value, call then() on the promise.

YUI({
    gallery: 'gallery-2013.05.10-00-54'
}).use('gallery-io-utils', function (Y) {

    var template = Y.Templates.someTemplate,
        node = Y.one('#foo');
    
    Y.io.getJSON('/foo').then(function (data) {
        node.setHTML(template(data)));
    });

});

List of utilities

Method Description Requirements
Y.io.xhr Makes an Ajax request
Y.io.get Makes an Ajax request with HTTP method GET
Y.io.post Makes an Ajax request with HTTP method POST
Y.io.put Makes an Ajax request with HTTP method PUT
Y.io.delete Makes an Ajax request with HTTP method DELETE
Y.io.DELETE Alias for Y.io.delete
Y.io.json Makes an Ajax request and parses the result as JSON The json-parse module
Y.io.getJSON Makes an Ajax request with HTTP method GET and parses the result as JSON The json-parse module
Y.io.postJSON Makes an Ajax request with HTTP method PST and parses the result as JSON The json-parse module
Y.io.putJSON Makes an Ajax request with HTTP method PUT and parses the result as JSON The json-parse module
Y.io.deleteJSON Makes an Ajax request with HTTP method DELETE and parses the result as JSON The json-parse module
Y.io.jsonp Makes a JSONP request The jsonp module
Y.io.script Loads a script
Y.io.css Loads a CSS stylesheet
Y.io.postForm Makes a POST Ajax request with the content of the provided form

Release notes

Next

  • Deprecated Y.io.DELETE in favor of Y.io.del
  • Y.io.postJSON and Y.io.putJSON now take an object as a second parameter that gets sent as JSON data to the server
  • Fixes broken requirements
  • Requirements are broken in this version