1.2.2 • Published 9 years ago

meanie-angular-http-buffer v1.2.2

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

meanie-angular-http-buffer

npm version node dependencies github issues codacy

An Angular service for buffering HTTP requests

Meanie

Installation

You can install this package using npm:

npm install meanie-angular-http-buffer --save

Include the script node_modules/meanie-angular-http-buffer/release/meanie-angular-http-buffer.js in your build process, or add it via a <script> tag to your index.html:

<script src="node_modules/meanie-angular-http-buffer/release/meanie-angular-http-buffer.js"></script>

Add HttpBuffer.Service as a dependency for your app.

Usage

Buffer failed requests in a http interceptor:

//Module dependencies
angular.module('App.MyModule', [
  'HttpBuffer.Service'
])

//Config
.config(function($httpProvider) {
  $httpProvider.interceptors.push('Buffered401Interceptor');
})

//Interceptor factory
.factory('Buffered401Interceptor', function($q, $rootScope, $httpBuffer) {
  return {
    responseError: function(response) {

      //Intercept 401's
      if (response.status === 401 && !response.config.ignore401intercept) {
        var promise = $httpBuffer.store(response.config);
        $rootScope.$broadcast('auth.401', response);
        return promise;
      }

      //Return rejection
      return $q.reject(response);
    }
  };
});

Later retry or reject them:

$rootScope.on('auth.401', function(event, response) {

  //Use an Auth service to login again
  Auth.doLogin().then(function() {

    //Retry all buffered requests
    $httpBuffer.retryAll();
  }, function() {

    //Reject all buffered requests
    $httpBuffer.rejectAll();
  });
});

Issues & feature requests

Please report any bugs, issues, suggestions and feature requests in the meanie-angular-http-buffer issue tracker.

Contributing

Pull requests are welcome! If you would like to contribute to Meanie, please check out the Meanie contributing guidelines.

Credits

License

(MIT License)

Copyright 2015-2017, Adam Reis

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago