Admitting my newness to Angular.js and lack of experience with frameworks like Backbone or Knockout, I am venturing into building an application that interacts with a server using a RESTful API. After delving deep into the angular documentation and blog posts, I feel equipped to do it right.
I stumbled upon examples mostly utilizing $resource. It seems promising: with many built-in methods, designing your REST interface properly can eliminate the need for additional code.
However, my team and I are more accustomed to the JavaEE approach to the model layer: lightweight model classes (POJO, etc), DAO classes handling data persistence and retrieval, possibly a service layer between DAO and controllers. On the flip side, $resource in Angular creates something akin to active record.
I've brainstormed two ways to implement the DAO pattern in Angular:
- Starting from scratch, working at the $http abstraction level, implementing every method as an $http call while handling errors.
- Leveraging $resource objects as lightweight model classes and passing them to DAOs responsible for invoking actions like .$save(). Although not foolproof against misuse, this convention suffices for me.
The second approach appeals to me due to code reusability. $resource offers promise object functionality, which saves me from reinventing the wheel.
Now, onto the crucial queries: is an active record approach the only way to achieve efficient data access in Angular, Backbone, and similar tools? Has anyone experimented with integrating a DAO-like solution into their code and would care to share insights?
Additionally, is the $resource object equipped to handle errors, connection disruptions, and other issues effectively? Given these considerations, is it advisable to stick with $resource or begin at a lower level with $http?
Being in the project's early stages, I understand the gravity of this decision and aim to make the best choice for its longevity.