You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chernser edited this page Sep 22, 2012
·
2 revisions
Tuning Response
Object types (resource types) is core of any application logic. The most interaction with RESTful API is done by POST, GET, PUT, DELETE requests. By default response contains what database returns (only DELETE returns {removed: true}.
If you need to change this behavior, you need to write proxy function.
Proxy Function - is called before sending response to client. It accepts resource as parameter, and should return new resource presentation. If collection should be returned, proxy function is called for each item.
Proxy function is defined for each object type separately on the "Logic" tab of "Object Types" panel.
Simple example adding mark field 'mocked = true;':
function proxy(resource) {
resource.mocked = true;
return resource;
}
NOTE: function MUST have name 'proxy', because within application API code it is called by name:
...
eval(proxy_function_code);
var result = proxy(resource);
...