To create generic rest service click Create New Service and select "Generic" type.
Now click "Add custom implementation":
You will be asked to enter javascript implementation name. Let's write "customTwitterSearch".
New Javascript asset is created. It must be changed to:
precode
$t.customTwitterSearch = $t.createClass(null, {
Code: Select all
init : function(requestOptions) {
this.__requestOptions = $.extend({}, requestOptions);
},
process : function(settings) {
this.settings = settings;
if (this.__requestOptions.echo) {
settings.success(this.__requestOptions.echo);
} else {
$.ajax({
url: "http://search.twitter.com/search.json?q=help",
context: this,
dataType: "jsonp"
}).done(this.onAjaxDone).error(this.onAjaxError);
showSpinner();
}
},
onAjaxDone: function(data) {
//You can filter "data" here
this.settings.success(data);
this.settings.complete('success');
hideSpinner();
},
onAjaxError: function(jqXHR, textStatus, errorThrown) {
this.settings.error(jqXHR, textStatus, errorThrown);
this.settings.complete('error');
hideSpinner();
}
});
/code/pre
(here is same code with syntax highlighting)
In this implementation AJAX request is made to search tweets. In the function "onAjaxDone" you may write any code to change "data" variable. After modification of ajax retrieved response is passed to Appery as response data at line:
codethis.settings.success(data);/code