Waffle Recipes

How-To's and Tutorials for the ActiveWAFL Framework

How to Make a Call to Your Application's API

Posted Oct 4, 2014

You can call the Api asynchronously or synchronously with Javascript using the following two signatures:
Note: The symbols you see below as the function names are _ (single underscore) and __ (double underscore)

Asynchronous Ajax/Api Call
_(string call[, object requestObject, string sendToken, function callbackMethod, string method, boolean useDefaultJsonParser])
Synchronous Ajax/Api Call
__(string call[, object requestObject, string method, boolean useDefaultJsonParser])
Example Javascript calling the ApiMinimal Options
  1. //asynchronous call to DoSomeActionAndGetSomeData Api
  2. _("DoSomeActionAndGetSomeData");
  3.  
  4. //synchronous call to DoSomeOtherActionAndGetSomeData Api
  5. var responseObject = __("DoSomeOtherActionAndGetSomeData");
In this example, the call to DoSomeActionAndGetSomeData is made asynchronously and the call to DoSomeOtherActionAndGetSomeData is made synchronously, both with no additional arguments.
Example Javascript calling the ApiAll Options
  1. //asynchronous call to DoSomeActionAndGetSomeData Api
  2. _("DoSomeActionAndGetSomeData", { "SomeProperty":"SomeValue"  }, "SomeUniqueToken",
  3.    function(responseObject, sendToken)
  4.    {
  5.       console.log("call " + sendToken + " complete.  Response: ");
  6.       console.log(responseObject);
  7.    }, "post", true);
  8.  
  9. //synchronous call to DoSomeOtherActionAndGetSomeData Api
  10. var responseObject = __("DoSomeOtherActionAndGetSomeData", { "SomeProperty":"SomeValue"  }, "post", true);
  11. console.log("synchronous call complete.  Response: ");
  12. console.log(responseObject);