Skip to content

Error when passing only path atributes on the REST #206

@masalinas

Description

@masalinas

I have the next problem:
First I have a method model defines like this:

    MyModel.remoteMethod (
        'sale',
        {
            description: "a model method example",
            accepts: [{arg: 'customerId', description: 'Customer Id', type: 'any', required: true, http: {source: 'path'}},
                      {arg: 'amount', description: 'Amount', type: 'any', required: true, http: {source: 'path'}}],
            returns: {arg: 'result', type: 'object', root: true},
            http: {verb: 'post', path: '/customers/:customerId/amount/:amount'}
        }
    );

This methos only pass path attributes. I created the angular counterpart using lb-ng and when I execute this method from javascript I obtain this error:

  MyModel.sale({customerId: customerId, amount: price})
                            .$promise
                            .then(function (value, responseHeaders) {
                                $.bigBox({
                                    title: "Plan Selected",
                                    content: "Your plan has been selected successfully",
                                    color: "#739E73",
                                    //timeout: 8000,
                                    icon: "fa fa-check",
                                    number: "1"});
                            }, function (httpResponse) {
                                var error = httpResponse.data.error;
                                console.log('Error login ' + error.status + ": " + error.message);
                            });

POST http://www.tachoexplorer.com:3000/services/rest/Braintrees/customers/amount 404 (Not Found)

The problem is that the lb-service not inject my attributes in the REST request. If use curl tool from shell the result is ok, so the problem is from client side.

If redesign my webservice like this, adding a stuff attribute on the body

MyModel.remoteMethod (
        'sale',
        {
            description: "a model method example with body attributes",
            accepts: [{arg: 'customerId', description: 'Customer Id', type: 'any', required: true, http: {source: 'path'}},
                      {arg: 'amount', description: 'Amount', type: 'any', required: true, http: {source: 'path'}},
                      {arg: 'stuf', description: 'Stuff attribute', type: 'object', required: true, http: {source: 'body'}}],
            returns: {arg: 'result', type: 'object', root: true},
            http: {verb: 'post', path: '/customers/:customerId/amount/:amount'}
        }
    );

And create again the counterpart in angular and called it again, now not exist any problem

MyModel.sale({customerId: customerId, amount: price}, {stuff: {}})
                            .$promise
                            .then(function (value, responseHeaders) {
                                $.bigBox({
                                    title: "Plan Selected",
                                    content: "Your plan has been selected successfully",
                                    color: "#739E73",
                                    //timeout: 8000,
                                    icon: "fa fa-check",
                                    number: "1"});
                            }, function (httpResponse) {
                                var error = httpResponse.data.error;
                                console.log('Error login ' + error.status + ": " + error.message);
                            });

The problem seems to be than I need to add any body attribute in my method to runs ok, meaby it

Also if a reconfigure again my method model using GET and not POST the result is ok, in that case with any stuff body attribute.

Could be a bug?? or I am making something wrong.

Regards

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions