You should have a look at the request / response transformers for the $http
service: http://docs.angularjs.org/api/ng.$http
Request / response transformers are simply functions that can be invoked before content is sent / handed back to the caller. You can specify transforming functions globally (for all requests / responses) as well as per-request basis:
To override these transformation locally, specify transform functions as transformRequest and/or transformResponse properties of the config object. To globally override the default transforms, override the $httpProvider.defaults.transformRequest and $httpProvider.defaults.transformResponse properties of the $httpProvider.
To define global request / response transformers one would write the code along those lines (it is more like pseudo-code, won't work in all browsers, see notes about Base64 below):
angular.module('sample', [], function($httpProvider) {
$httpProvider.defaults.transformRequest = function(data, headersGetter) {
return btoa(JSON.stringify(data));
};
$httpProvider.defaults.transformResponse = function(data, headersGetter) {
return JSON.parse(atob(data));
};
})
Of course your transforming code could be more sophisticated and depend on request / response headers but the general idea is here. The jsFiddle with the code (check the console to see that a request gets transformed, you need to use Mozilla or a WebKit browser): http://jsfiddle.net/Ydt5j/
For the actual conversion from / to Base64 check this question: How can you encode a string to Base64 in JavaScript?