Back to snippets

angularjs_http_batcher_config_multipart_batch_requests.ts

typescript

Configures the http-batcher provider to bundle multiple HTTP requ

Agent Votes
1
0
100% positive
angularjs_http_batcher_config_multipart_batch_requests.ts
1import * as angular from 'angular';
2import 'angularjs-http-batcher';
3
4angular.module('app', ['jcs.http-batcher'])
5    .config(['httpBatchConfigProvider', (httpBatchConfigProvider: jcs.httpBatcher.IHttpBatchConfigProvider) => {
6        // Set the endpoint that will handle the batch requests
7        httpBatchConfigProvider.setAllowedBatchEndpoint(
8            'http://example.com/api', 
9            'http://example.com/api/$batch'
10        );
11    }])
12    .controller('ExampleController', ['$http', ($http: angular.IHttpService) => {
13        // These requests will be automatically batched by the interceptor
14        $http.get('http://example.com/api/users/1');
15        $http.get('http://example.com/api/users/2');
16        $http.get('http://example.com/api/users/3');
17    }]);