Socket
Book a DemoInstallSign in
Socket

salte-angular-hateoas

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

salte-angular-hateoas

The simple way to consume HATEOAS enabled REST APIs with AngularJS

1.1.8
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
Source

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

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.

Keywords

angular

FAQs

Package last updated on 01 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.