Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple JsonAPi adapter for Restangular
// it require either lodash or underscorejs
.config(function(RestangularProvider) {
// add a response interceptor
RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
extractedData =;
extractedData.meta = data.meta;
extractedData.included = data.included;
function _apply(elem, fct){
if(elem !== undefined){
if(elem.type !== undefined){
_.forEach(elem, function(el){
_apply(el, fct);
_apply(, function(elem){
_apply(elem.relationships, function(rel){
rel.getIncluded = function(){
return _.find(extractedData.included, function(included){
a = included.type == rel.type;
b = ==;
return a && b;
return extractedData;
//simply call getIncluded on a relationship object and bam!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment