Skip to main content
1 of 3
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60

###Async usage pattern

All query methods use the following typical async pattern

//

site.Badges().invoke(function onSuccess(items, userContext, methodName) {

    // handle items array of domain objects
    // if linq.js is loaded the items array will be an instance of
    // Enumerable<domain object>

}, function onFailed(error, userContext, methodName) {

    // handle error - which looks like this:

    //    error : {
    //        message: "the message",
    //        code: 500, // the status code
    //        url: "the url that failed"
    //    };


}, { someUserContext: "foo" });

//

The static ApiProxy provides a place to hang default/global handlers. Certain application structures lend themselves well to a centralized response handler.

// on Soapi.Net.ApiProxy, you may set default callbacks. e.g.

Soapi.Net.ApiProxy
 .set_defaultSucceededCallback(function(data, userContext, methodName) {
    // default response handler
});

Soapi.Net.ApiProxy
 .set_defaultFailedCallback(function(error, userContext, methodName) {
    // default error handler
});
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60