The datasource util

Purpose

Use this class to make HTTP requests and parse their results in JSON or JSONP.

Implementation

In the browser adapter, DataSource.request() uses jQuery.ajax and accepts the same parameter format excepted the callbacks, to stay coherent with Joshfire's conventions:


  // jQuery.ajax code
  jQuery.ajax({
    url:"/api/session",
    type:"POST",
    success:function(data) {
      console.log("success!");
    },
    error:function() {
      console.log("error!");
    }
  });
  
  // Equivalent DataSource code
  var ds = new DataSource();
  ds.request({
    url:"/api/session",
    type:"POST"
  },function(error,data) {
    if (error) {
      console.log("error!");
      return;
    }
    console.log("success!");
  });
  

In the node adapter, most of the options of DataSource.request() are implemented using the request npm module and we target 100% compatibility in the future.

For more details checkout the API documentation