Have ideas to improve npm?Join in the discussion! »

    angular-extended-resource

    1.0.2 • Public • Published

    angular-extended-resource

    Build Status Coverage Status

    Description

    Angular extended resource is a wrapper for Angular ngResouce. It provide a simple way to fetch resource from localStorage to provide a quick "stale" response, and let the original resource fetching data from real API. And to extract responses from a sub object:

    The diference with the cache option are:

    • the promise is not canceled
    • data are stored in localStorage instead of memory.

    Demo available on github.io pages

    Install

    Install with bower:

    bower install angular-extended-resource

    Add a <script> to your index.html:

    <script src="/bower_components/angular-extended-resource/angular-extended-resource.js"></script>

    And add exResource as a dependency for your app:

    angular.module('myApp', ['exResource']);

    Differences with angular-resource

    // angular resource
    angular.module('myApp', ['ngResource']);
     
    // angular extended resource
    angular.module('myApp', ['exResource']);
    // angular resource
    app.factory('Customer', function($resource) {
      return $resource('/api/customers/:id', {id: '@id'});
    })
     
    // angular extended resource
    app.factory('Customer', function($xResouce) {
      return $xResouce('/api/customers/:id', {id: '@id'});
    })

    Easy isn't it?

    Basic AccessPropery Usage

    .factory('Customer', function($xResouce) {
      return $xResouce('/api/customers/:id', {id: '@id'}, {
        'get':    {method:'GET', $accessProperty: 'customer'},
        'query':  {method:'GET', $accessProperty: 'customers', isArray:true},
        'save':   {method:'POST', $accessProperty: 'customer'},
        'delete': {method:'DELETE'},
      });
    })

    Advanced documentation on dedicated project page

    Basic Cache Usage

    .factory('Customer', function($xResouce) {
      return $xResouce('/api/customers/:id', {id: '@id'}, {
        'get':   {method:'GET', $cache: true},
        'query': {method:'GET', $cache: false, isArray:true},
      });
    })

    Advanced documentation on dedicated project page

    Author

    Jérémy Derussé, https://github.com/jeremy-derusse

    Last Version

    v1.0.2

    Contributors

    Change Log

    • v1.0.2

      • Fix garbage collector TTL
    • v1.0.1

      • Merge resource with previous cached value.
      • Fix split on null value
      • Optimize GC
    • v1.0.0

      • Initial version.

    License

    The MIT License (MIT)

    Copyright (c) 2014 Jérémy Derussé

    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.

    Install

    npm i angular-extended-resource

    DownloadsWeekly Downloads

    0

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • avatar