Unitech / angular-bridge

Link models easily via a REST interface between Mongoose/Node-Express/Angular.js
207 stars 22 forks source link

This library is awesome but it has nothing to do with angular :P #13

Open nickretallack opened 10 years ago

nickretallack commented 10 years ago

This appears to be an implementation of the Rails Resource pattern. I like it. It saves a lot of boilerplate code at the beginning of a project. I just downloaded mean.io and replaced the articles controller with a one-liner. This is awesome!

Specifically, I edited mean/config/routes.js. I removed this:

    var articles = require('../app/controllers/articles');
    app.get('/articles', articles.all);
    app.post('/articles', auth.requiresLogin, articles.create);
    app.get('/articles/:articleId', articles.show);
    app.put('/articles/:articleId', auth.requiresLogin, auth.article.hasAuthorization, articles.update);
    app.del('/articles/:articleId', auth.requiresLogin, auth.article.hasAuthorization, articles.destroy);

    //Finish with setting up the articleId param
    app.param('articleId', articles.article);

and I added this:

    var bridge = new (require('angular-bridge'))(app, {
        urlPrefix : '/'
    });
    var mongoose = require('mongoose')
    var Article = mongoose.model('Article')
    bridge.addResource('articles', Article)

This allowed me to throw away this file and the application still worked fine.

This API could be consumed by anything. There's nothing angular-specific about it. Perhaps the project should be renamed, unless you intend to do some tighter integration with Angular. Perhaps you already have plans for this?

One kind of integration I'd love to see would be to allow you to re-use Mongoose schemas in the browser to automatically generate your $resources. It would be nice if validations were available and introspectable in the browser so they could be integrated with angular's form validation.

konsumer commented 8 years ago

I use it with react & this. Very useful in a non-angular context.