Transformation functions
Transforamtion functions are used to format the data before sending the request to the server and after recieveing the response from the server. Let's suppose that you are using two different Servces in your Application and the data is coming in the format given below.

Although the data from both the Services is similar and represents the same piece of information but only the property names are different. To sort out this data in your Application is difficult and may be a mess in your Application code. Transformation functions provide a solution to this problem by reading the data from each Service and transforming it into one data format.
After transformation, the propertis are standarized and you can easily manipulate the data. Angular provides default transformation for the request and response and they can be accessed through $http.default object.
Transform Response
Syntax
- $http({
- url: '',
- method: 'GET',
- transformResponse: function(data, headersGetter,status) {
- //the first paramter is the data which is coming back from server
- //headersGetter paramater povides access to header object
- //third parameter is status code which is available on above 1.3.7 AngularJS version
- return transformedObject;
- }
- }).then(function(response) {
- //do some stuff here
- }).catch(function(){
- //do some stuff here
- });
Transform Request
Syntax

Join the conversation! Your thoughts help the community grow.