YUILibrary - Open source JavaScript and CSS for building richly interactive software.
Fork YUI on GitHub
  • Home
  • Gallery
  • Forums
  • YUI 2
  • YUI 3
  • YUI Compressor
  • YUI Doc
  • More
  • Gallery Forums
  • Gallery Stats
  • Gallery Calendar
  • Register
  • Login

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • FAQ
  • Developer FAQ
  • Developer Guide
  • Module Setup

Tag Cloud

plugin animation port jafl yui2 adam event node caridy lsmith jsonp foxxtrot html5 filter nzakas apipkin ajax skinnable widget form slideshow io overlay davglass rgrove ericf

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    REST Resource (gallery-resource) on cdn

    Last Updated: 03/29/10
    + 3 -

    Eric Ferraiuolo

    YUI Contributor

    See 6 more by this user.

    Created: 12/15/09
    Last CDN Push: 03/30/10
    Build Tag: gallery-2010.03.30-17-26
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.1.0 PR2
    Free for use.

    --I'll write more here soon--

    Features Custom Event hooks for each instance (fired for every request) and per-request callbacks, convenience methods for HTTP verbs, entity translations (i.e. Object/Array -- JSON, JSON -- Object/Array) based on Content-Type header, parameter convenience.

    • Tags:
    • http
    • rest
    • io
    • ericf
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Code Sample

    <script src="http://yui.yahooapis.com/3.1.0/build/yui/yui-min.js"></script>
    // *** Simple Example *** //
     
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2010.03.30-17-26'
    }).use('gallery-resource', function(Y) {
     
    	var r = new Y.Resource({ uri: 'path/to/resource/{id}' });
     
    	r.GET({	// makes request to: path/to/resource/1?format=json
    		params	: { id: 1, format: 'json' },
    		on	: {
    			success : function(e){
    				// e.entity is an Object parsed from the JSON returned by the server
    			}
    		}
    	});
     
    });
     
     
    // *** Complex Example *** //
     
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2010.03.30-17-26'
    }).use('gallery-resource', function(Y) {
     
    	var r = new Y.Resource({
    		uri	: 'path/to/resource/{id}',
    		headers	: {
    			'Content-Type'	: 'application/json',
    			'Accept'	: 'application/json'
    		},
    		on	: {
     
    			request		: logRequest,
    			deleteRequest	: function(e) {
    				e.preventDefault();	// umm, no, you can't do that!
    			},
    			response	: logResposne,
    			getSuccess	: logParsedJSONEntity
     
    		}
    	});
     
    	r.DELETE({ params: { id: 1 } }); // will be prevented
     
    	r.GET({ params: { id: 1, format: 'json' } }); // io request to: path/to/resource/1?format=json
     
    	r.GET({
    		params	: { id: 2 },
    		on	: {
    			success : function(e){
    				Y.log('Only called for this request', 'info');
    			}
    		}
    	});
     
     
    	function logRequest (e) {
    		Y.log('request params: '+e.params, 'info');
    	}
     
    	function logResponse (e) {
    		Y.log('response status: '+e.response.status, 'info');
    		Y.log('request parmas: '+e.request.params, 'info');
    	}
     
    	function logParsedJSONEntity (e) {
    		var entity = e.entity;
    		Y.log('parsed JSON: '+(Y.Lang.isObject(entity) || Y.Lang.isArray(entity)), 'info');
    	}
     
    });
     

    Forum Posts

    No forum posts for this module.

    YUI Projects
    • All YUI Downloads
    • YUI 2
    • YUI 3
    • YUI Doc
    • YUI Compressor
    • YUILibrary.com
    • YUI Build Tool
    • YUI PHP Loader
    Pages & Links
    • All YUI Downloads
    • Git FAQ
    • Graded Browser Support
    • Contribute to YUI
    • Forum Stats
    • Gallery Stats
    • YUI Calendar
    Contribute
    • Submit a Bug
    • Request a Feature
    • Write Code
    • Meet the Team
    Follow YUI
    • on GitHub
    • on Twitter
    • on FriendFeed
    • on Facebook
    • on IRC
    • YUI Blog
    • YUI Theater
    • YUI Forums

    © 2010 YUI Library - Site Credits