angular-model-factory

angular-model-factory makes working with RESTful APIs in AngularJS easy!

Angular Core Dependency: 1.3.x

Module License: MIT

Added by: Sam Deering

GitHub

Repository

swimlane/angular-model-factory

Stats

Stars: 238

Watchers: 238

Forks: 33

Author

Swimlane
Swimlane

Module Description

modelFactory Build Status Codacy Badge

A light-weight model layer that bridges the gap between AngularJS and your RESTful APIs.

Why would you use this over other available solutions?

  • Lightweight/Simple, the code simply does some basic copy/extending and prototypical instances; no magic required.
  • Patterns/Practices, the model definition closely resembles Angular's ngResource meaning its easy to swap out, replace later, eases scaling/transition, and its designed for Angular; not a backbone port!
  • Utilizes Angular at the core, it doesn't duplicate things Angular already does. Any action can be passed a $http configuration option, all your interceptors still work, it uses Angular's cache, etc!
  • Compliant, URI Template matches the specs.
  • Small - 1.45KB gzipped/minified ( excludes depedencies )
  • Minimal Dependencies, only use URI template and deep-diff ( this isn't even required ) utility. NO underscore, lodash, jquery, etc!
  • Its full of awesome features

See wiki for documentation.

Features

  • URI Templates (RFC6570)
  • Model instances
  • Collections
  • Single Datastore
  • Caching / Cache invalidation
  • Default value population
  • Pending / Completed Status
  • Relationships
  • Object Deep Diff / Reversion
  • Track active promises to prevent duplicate sends

Other Solutions

After doing quite a bit of research before writing this, I took a look at other solutions. Here is what I found and why I wrote my own.

  • Restmod Very nice solution but very opinionated and hyper-active. 22kb min

  • Modelizer Good but requires Lodash. 23kb min

  • ModelCore Good but not very well tested and not active.

  • angular-watch-resource - Really only handles collections

  • angular-restful - Very basic but nice

  • ngResource Out of the box model layer, very limited.

  • angularjs-rails-resource Too rails-ish.

  • angular-nested-resource - Okay API, not loving the nested architecture.

  • Aar.js Very light, not sure what value this adds.

  • Angular Activerecord A copy of BackboneModel but doesn't really work with Angular patterns.

  • Angular-Data Not really a model layer but a data store. Very very heavy ( 67kb min )

  • ngActiveResource Very ruby-ish api. Requires lodash. Has validation but thats not needed in angular if you do it right.

  • restangular I don't consider this a model layer; it feels moore like a fancy http layer that returns promises because everyone complains about ngResource not doing it. It requires underscore.

  • BreezeJS This is a very full featured model/cache/validation etc. Its framework agnostic, which means it follows its own patterns and not angulars. Its very heavy, requires server data massaging, and the API looks like Microsoft Entity Framework.

  • ng-backbone Another backbone model clone. This one actually requires backbone and lodash.

Dependencies

Development

Prepare your environment

  • Install Node.js and NPM (should come with)
  • Install global dev dependencies: npm install -g bower grunt-cli
  • Install local dev dependencies: npm install && bower install in repository directory

Development Commands

  • grunt build to concat and build
  • grunt karma for continuous testing mode with karma (useful during development as tests will be run on each change)
  • grunt karma:ci for a one-time execution of the tests (used by Travis)

Contributing

  • Run the tests
  • Create a feature branch
  • When issuing a pull request, please exclude changes from the "dist" folder to avoid merge conflicts.

Module stats last updated: 2017-08-08 15:00:05

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!