//Server PHP
utils::secureRoute(
$app->post('/api/product','\Your\NameSpace\ProductController:handle'),//Register your API url and set a method to handle it.
['productManager','admin'],//Current user must have these roles.
'image',//Current request must have correct image captcha.
['product' => ['select','update','delete','insert']]//Client can directly access specified database table and actions under this API.
);
//Client JavaScript
angular.ASPAModule('app',['AliceSPA'])//AliceSPA extend AngularJS with new features.
.run(['ASPADirectDatabaseService','ASPAAPIProtocolService','ASPADirectiveHandleService',function(ASPADirectDatabaseService,ASPAAPIProtocolService,ASPADirectiveHandleService){//Inject AliceSPA services.
ASPADirectDatabaseService.select('/api/product','product','*',{'create_date[>]':'2016-09-04 15:36:00'})//SELECT * FROM product WHERE create_date > "2016-09-04 15:36:00"
.then(
function(successData){
},
function(failureErrors){
}
);
var imageCaptchaId = ASPADirectiveHandleService.getASPACaptchaImageHandle('myHandle').id;//Get handle with dynamic generated method.
var options = ASPAAPIProtocolService.makeImageCaptchaOptions(null,imageCaptchaId,'captchaCode');//Fill in addons.
ASPAAPIProtocolService.post('/api/product/add',{'name':'productName','price':23},null,options).then(//Send request and AliceSPA will check roles and captcha.
function(successData){
},
function(failureErrors){
}
);
}]);