old | new |
---|---|
halClient.$* | $http() |
halClient.LinkHeader | LinkHeader |
resource.$[method] | resource.$request().$[method] |
npm install angular-hal --save
bower install angular-hal
Reference the js files in your html page
<script src="bower_components/rfc6570/rfc6570.js"></script>
<script src="bower_components/angular-hal/angular-hal(.min).js"></script>
You may use it like this:
angular
.module('app', ['angular-hal'])
.run(function($rootScope) {
$rootScope.apiRoot = $http({url: 'https://api.example.com/'});
$rootScope.$watch('apiRoot', function(apiRoot){
$rootScope.authenticatedUser = apiRoot.$request().$get('http://example.com/authenticated-user');
});
}]);
stay tuned for more!
Use the provider $halConfigurationProvider
to configure the module.
setLinksAttribute
- Set links attribute name. (default:_links
)setEmbeddedAttribute
- Set embedded attribute name. (default:_embedded
)setIgnoreAttributePrefixes
- Set prefix for meta (hidden) properties. (default:[ '_', '$' ]
)addIgnoreAttributePrefix
- Add a prefix.setSelfLink
- Set name of self link. (default:self
)setForceJSONResource
- Force transformation of JSON response into HAL resource. (default:false
, !this may break other modules!)setUrlTransformer
- Set a function to change urls. (deprecated)
- A blog post by Yuan Ji about Angular-HAL
- Role-based SPAs with AngularJS and Spring HATEOAS
- Hypermedia REST API client for AngularJS applications
If you wish to use this service in old (ie) browsers, you may need to use the following polyfills:
- es5shim & es5sham, https://github.com/kriskowal/es5-shim, some parts of the service use es5 methods.
- xhr-polyfill, https://github.com/LuvDaSun/xhr-polyfill, if you want to make cross domain requests in ie8 / ie9.