Demo - calling Alma APIs using AngularJS - http.get/ngResource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html ng-app="exampleApp"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Example - GET using AngularJS</title> | |
<!-- based on http://www.apress.com/9781430264484 listing 20-3 --> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script> | |
<script> | |
angular.module("exampleApp", []) | |
.controller("defaultCtrl", function ($scope, $http) { | |
$scope.loadData = function () { | |
$http.get("https://api-na.hosted.exlibrisgroup.com/proxy_to_gw/almaws/v1/partners?format=json").success(function (data) { | |
// Note the "proxy_to_gw" in the URL above. We can't pull the data directly from a regular call to the gateway so we proxy the requests via a server which then adds the API-key and forwards the request. Make sure that the API-key hs permission only to read-only data which isn't a "secret". More details here: https://developers.exlibrisgroup.com/forum/posts/list/41.page | |
console.log(JSON.stringify(data)); | |
// the data comes from Alma as an array which is named "partner". | |
$scope.items = data.partner; | |
}); | |
} | |
}); | |
</script> | |
</head> | |
<body ng-controller="defaultCtrl"> | |
<button ng-click="loadData()">Load Data</button> | |
<table border=1> | |
<thead><tr><th>Name</th><th>Code</th><th>Status</th></tr></thead> | |
<tbody> | |
<tr ng-hide="items.length"> | |
<td colspan="3">No Data</td> | |
</tr> | |
<tr ng-repeat="item in items"> | |
<td>{{item.partner_details.name}}</td> | |
<td>{{item.partner_details.code}}</td> | |
<td>{{item.partner_details.status}}</td> | |
</tr> | |
</tbody> | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html ng-app="exampleApp"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Example - GET using AngularJS and angular-route</title> | |
<!-- based on http://www.apress.com/9781430264484 listing 21-14 --> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-resource.js"></script> | |
<script> | |
angular.module("exampleApp", ["ngResource"]) | |
.controller("defaultCtrl", function ($scope, $resource) { | |
var baseUrl = "https://api-na.hosted.exlibrisgroup.com/proxy_to_gw/almaws/v1/partners"; | |
// Note the "proxy_to_gw" in the URL above. We can't pull the data directly from a regular call to the gateway so we proxy the requests via a server which then adds the API-key and forwards the request. Make sure that the API-key hs permission only to read-only data which isn't a "secret". More details here: https://developers.exlibrisgroup.com/forum/posts/list/41.page | |
$scope.itemsResource = $resource(baseUrl + ":id", { id: "@id", format:'json' } ); | |
$scope.loadData = function () { | |
// we use get() and not query() because of http://stackoverflow.com/questions/26093003/response-does-not-match-configured-parameter | |
$scope.items = $scope.itemsResource.get(); | |
} | |
}); | |
</script> | |
</head> | |
<body ng-controller="defaultCtrl"> | |
<button ng-click="loadData()">Load Data</button> | |
<table border=1> | |
<thead><tr><th>Name</th><th>Code</th><th>Status</th></tr></thead> | |
<tbody> | |
<tr ng-hide="items.partner.length"> | |
<td colspan="3">No Data</td> | |
</tr> | |
<!-- the data comes from Alma as an array which is named "partner" --> | |
<tr ng-repeat="item in items.partner"> | |
<td>{{item.partner_details.name}}</td> | |
<td>{{item.partner_details.code}}</td> | |
<td>{{item.partner_details.status}}</td> | |
</tr> | |
</tbody> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment