Angular Hateoas


The simple way to consume HATEOAS enabled REST APIs with AngularJS
Installation
$ npm install salte-angular-hateoas
Usage
Enabling HATEOAS support is as simple as adding a dependency on salte-angular-hateoas
to your application and pushing an interceptor.
NOTE: This will ONLY convert objects that return with the, "application/hal+json", Content-Type
var app = angular.module('app', ['salte-angular-hateoas']);
app.config(function($httpProvider) {
$httpProvider.interceptors.push('hateoasInterceptor');
});
API
$get(key, [config])
key
: The link key
config
: Optional configuration object (identical to $http's config)
Returns a $http GET request for the designated link
$http.get('/api/some-hateoas-endpoint').then(function(data) {
data.$get('self').then(function(self) {
});
});
$post(key, data, [config])
key
: The link key
data
: Request content
config
: Optional configuration object (identical to $http's config)
Returns a $http POST request for the designated link
$http.get('/api/some-hateoas-endpoint').then(function(data) {
data.$post('self', data).then(function(self) {
});
});
$put(key, data, [config])
key
: The link key
data
: Request content
config
: Optional configuration object (identical to $http's config)
Returns a $http PUT request for the designated link
$http.get('/api/some-hateoas-endpoint').then(function(data) {
data.$put('self', data).then(function(self) {
});
});
$patch(key, data, [config])
key
: The link key
data
: Request content
config
: Optional configuration object (identical to $http's config)
Returns a $http PATCH request for the designated link
$http.get('/api/some-hateoas-endpoint').then(function(data) {
data.$patch('self', data).then(function(self) {
});
});
$delete(key, [config])
key
: The link key
config
: Optional configuration object (identical to $http's config)
Returns a $http DELETE request for the designated link
$http.get('/api/some-hateoas-endpoint').then(function(data) {
data.$delete('self', { data: data }).then(function(self) {
});
});
$embedded(key)
key
: refers to the embedded key
Returns a promise which resolves to an embedded object.
$http.get('/api/some-hateoas-endpoint').then(function(data) {
data.$embedded('list').then(function(list) {
});
});
$link(key)
Returns a promise which resolves to a link.
$http.get('/api/some-hateoas-endpoint').then(function(data) {
data.$link('self').then(function(self) {
});
});
config
Setting the links
key
app.config(function($hateoasConfigProvider) {
$hateoasConfigProvider.setLinksKey('related');
});
Setting the embedded
key
app.config(function($hateoasConfigProvider) {
$hateoasConfigProvider.setEmbeddedKey('content');
});
Disabling readonly
mode
app.config(function($hateoasConfigProvider) {
$hateoasConfigProvider.setReadOnly(false);
});
License
The MIT License
Copyright (c) 2016 Salte. https://www.salte.io
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.