-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.html
76 lines (65 loc) · 2.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html ng-app="httpBatchExample">
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div ng-controller="mainCtrl">
<button type="button" ng-click="callSingle();">Call Single API Method</button>
<button type="button" ng-click="callMultiple();">Call Multiple API Methods (Which will be batched)</button>
</div>
<!--<script src="../bower_components/angular/angular.js"></script>-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="../dist/angular-http-batch.js"></script>
<!--<script src="../src/angular-http-batch.js"></script>-->
<!--<script src="../src/providers/httpBatchConfig.js"></script>-->
<!--<script src="../src/services/httpBatcher.js"></script>-->
<!--<script src="../src/config/httpBackendDecorator.js"></script>-->
<script type="text/javascript">
var app = angular.module('httpBatchExample', [window.ahb.name]);
app.config([
'httpBatchConfigProvider',
function (httpBatchConfigProvider) {
httpBatchConfigProvider.setAllowedBatchEndpoint(
'http://localhost:8080',
'http://localhost:8080/api/batch', {
batchRequestCollectionDelay: 500
});
}
]);
app.controller('mainCtrl', [
'$scope',
'$http',
function ($scope, $http) {
$scope.callMultiple = function () {
$http.get('http://localhost:8080/api/products').then(function (data) {
console.log('success on batch call No.0 - ' + data.data);
}, function (err) {
console.log('error on batch call No.0 - ' + err);
});
$http.get('http://localhost:8080/api/products/2').then(function (data) {
console.log('success on batch call No.1 - ' + data.data);
}, function (err) {
console.log('error on batch call No.1 - ' + err);
});
$http.put('http://localhost:8080/api/products', {
Name: 'Product X',
StockQuantity: 300
}).then(function (data) {
console.log('success on batch call No.2 - ' + data.data);
}, function (err) {
console.log('error on batch call No.2 (This is expected - just to illustrate an error in one of the batched requests) - ' + angular.fromJson(err));
});
};
$scope.callSingle = function () {
$http.get('http://localhost:8080/api/products').then(function (data) {
console.log('success on single call No.0 - ' + data.data);
}, function (err) {
console.log('error on single call No.0 - ' + err);
});
};
}]);
</script>
</body>
</html>