angular-bridge icon indicating copy to clipboard operation
angular-bridge copied to clipboard

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

Open nickretallack opened this issue 11 years ago • 1 comments

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.

nickretallack avatar Nov 15 '13 23:11 nickretallack

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

konsumer avatar Aug 08 '16 21:08 konsumer