How to implement Restangular in a MEAN.js application?

Issue

I would like to figure out how to implement Restangular in my mean.js application, i’m doing the routing with angular.js, and i’m using espress.js for the RESTAPI, what i want is to consume the API with Restangular.

These are some of my express routes:

module.exports = (function () {

    var express        = require( 'express' ),
        router         = express.Router(),
        create_product = require( './create-product.controller' ),
        list_product   = require( './list-product.controller' ),
        detail_product = require( './detail-product.controller' ),
        update_product = require( './update-product.controller' );

    router.route( '/purchases/products/new' )
        .post( create_product.post );

    router.route( '/purchases/products/list' )
        .get( list_product.get );

    router.route( '/purchases/products/:id/detail' )
        .get( detail_product.get );

    router.route( '/purchases/products/:id/update' )
        .put( update_product.put );

    return router;

})();

When using $http i would do:

$http.get('/purchases/products/list').then(successCallback, errorCallback);

$http.post('/purchases/products/1/update', {name: 'Eggs', description: 'White'}).then(successCallback, errorCallback);

How could i do that using Restangular?

Solution

I dont know if you actually read the documentation but

Restangular.all('purchases/products/list').getList().then(success,err);

Or

Restangular.all('purchases').all('products').all('list').getList().then(sucess,err);

Same for post

Restangular.all('purchases/products/1/update').post(data).then(success,error)

Answered By – Milos Mosovsky

Answer Checked By – David Goodson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.