This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

salte-angular-hateoas

1.1.8 • Public • Published

Angular Hateoas

NPM Version NPM Downloads CI Build Coveralls

semantic-release

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) {
    // This will only intercept requests
    $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) {
        // This will return the resulting GET of the self link.
    });
});

$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) {
        // This will send a POST to the self link with a request body containing the data object.
    });
});

$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) {
        // This will send a PUT to the self link with a request body containing the data object.
    });
});

$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) {
        // This will send a PATCH to the self link with a request body containing the data object.
    });
});

$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) {
        // This will send a DELETE to the self link with a request body containing the data object.
    });
});

$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) {
        // This will return the resulting embedded object with the key list.
    });
});

$link(key)

  • key: The 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) {
        // This will return the resulting href of the self link.
    });
});

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.

Package Sidebar

Install

npm i salte-angular-hateoas

Weekly Downloads

2

Version

1.1.8

License

MIT

Unpacked Size

52.3 kB

Total Files

8

Last publish

Collaborators

  • ceci-woodward
  • salte-bot