Skip to content

Instantly share code, notes, and snippets.

@mgonto
Created April 27, 2013 01:39
Show Gist options
  • Select an option

  • Save mgonto/5471539 to your computer and use it in GitHub Desktop.

Select an option

Save mgonto/5471539 to your computer and use it in GitHub Desktop.
restangular Custom 2
//In your app configuration (config method)
RestangularProvider.setOnElemRestangularized(function(elem, isCollection, route) {
if (!isCollection && route === "buildings") {
// This will add a method called evaluate that will do a get to path evaluate with NO default
// query params and with some default header
// signature is (name, operation, path, params, headers, elementToPost)
elem.addRestangularMethod('evaluate', 'get', 'evaluate', undefined, {'myHeader': 'value'});
}
return elem;
})
// Then, later in your code you can do the following:
//GET to /buildings/123/evaluate?myParam=param with headers myHeader: value
//Signature for this "custom created" methods is (params, headers, elem)
// If something is set to any of this variables, the default set in the method creation will be overrided
// If nothing is set, then the defaults are sent
building.evaluate({myParam: 'param'});
//GET to /buildings/123/evaluate?myParam=param with headers myHeader: specialHeaderCase
building.evaluate({myParam: 'param'}, {'myHeader': 'specialHeaderCase'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment