The job of a transformer or a transformer function is to transform the input data from one format to another. These transformers plug into the HTTP request/response processing pipeline of Angular and can alter the message received or sent. A good example of the transformation function usage is AngularJS global transformers that are responsible for converting a JSON string response into a JavaScript object and vice versa.
Since data transformation can be done while making a request or processing a response, there are two transformer pipelines available, one for a request and another for a response.
Transformer functions can be registered:
Globally for all requests/responses. The standard JSON string-object transformers are registered at a global level. To register global transformer function we need to push or shift a function either to the
$httpProvider.defaults.transformRequest
or$httpProvider.defaults.transformResponse
array. As always with a pipeline...