restful.js
restful.js copied to clipboard
Cannot add functions to response body data object
I would like to transform the result returned from the REST api and put some accessor functions on the object in order to transform the data when its accessed.
However, when I do this, it crashes my browser and only when the functions are removed, then it works as normal.
instance.addResponseInterceptor((response:any,config:any) => {
const { data, headers, statusCode } = response;
return {
data: RestClientData(data)
}
});
function RestClientData(data:any){
// this is a simple example, just to illustrate
return {
list: function() {
return data._embedded.items
}
}
}
This will cause the browser to crash out, but removing the function, will return it to working state.