Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9055641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:00:25+00:00 2026-06-16T14:00:25+00:00

Lets say i have several $resources and some $http around my angular application: myApp.factory(‘Note’,

  • 0

Lets say i have several $resources and some $http around my angular application:

myApp.factory('Note', function($resource) {

  return $resource('http://', {id: '@id'}, 
    { 'index': { method: 'GET', isArray: true },
      'update': { method: 'PUT'},
    });
  });

with controller

myApp.controller('NotesController',function NotesController($scope, Note, AuthenticationService) {

$scope.notes = Note.index({}, function(data){
    console.log('success, got data: ', data);
    $scope.response = "yoy!"
  }, function(err){
    console.log('error, got data: ', err);
    $scope.response = "yay!"
  }); 
});

and some request are made by $http directly like authentication

var request = $http.post('http://', {email: email, password: password});

Where and How i can tell angular to deflate and encode/decode JSONs to base64 before the actual request is made / response is receive?

I quess i will wrap external libraries for deflate and encode/decode into factory. And then this factory will be injected somehere?
Like $httpBackend ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:00:26+00:00Added an answer on June 16, 2026 at 2:00 pm

    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?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my iphone application I have several images. lets say some small square images.
Let's say we have a grails web application exposing several resources. tags urls users
Lets say I have several functions where I do some kind of animations and
I have an app that contains several activities...so lets say user is navigating activity
Let's say I have some Jinja2 template with several blocks in it: {% block
I have an app with support for several different languages. Now lets say I
Lets say I have several sets of options in Javascript var color = [red,
Lets say that I have several DevExpress controls and one of them is a
If I have a several header files :lets say 1.h , 2.h , 3.h
lets say I have an NSWindow Class, that has several events for mouse and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.