angular remote PUT method

38 views
Skip to first unread message

jmls

unread,
Oct 1, 2015, 5:00:47 PM10/1/15
to LoopbackJS
I have defined a model with the following remote :

   MyModel.remoteMethod(
       
'install',
       
{
            accepts
: [
             
{arg: 'foo', type: 'string'}
           
],
            description
: 'install new foo,
            returns: {arg: '
results', type: 'object',root: true},


            http: {path: '
/install/:foo', verb: 'put'}
        });


I have generated the services file

module.factory(
 
"MyModel",
 
['LoopBackResource', 'LoopBackAuth', '$injector', function(Resource, LoopBackAuth, $injector) {
   
var R = Resource(
      urlBase
+ "/MyModel/:id",
     
{ 'id': '@id' },
[snip]
 
/**
         * @ngdoc method
         * @name lbServices.MyModel#install
[snip]
"install": {
          url: urlBase + "/MyModel/install/:foo",
          method: "PUT"
        },


the explorer api works well (enter a foo, press "try it out!" and everything works just fine.

however, from within the angular client

  MyModel.install({foo: "something"}).$promise.then(function(err,result) {
                    console
.log(err,result)
               
})




always returns a 404

PUT https://myUrl/apiMyModel/install 404 (Not Found)

what am I doing wrong ?

thanks







jmls

unread,
Oct 1, 2015, 5:30:46 PM10/1/15
to LoopbackJS
**update#1**

whilst the explorer api works (put /MyModel/install, enter the "foo" argument) , the sdk craps out with the 404 error. Looking further, this is because loopback is bitching about the fact that 
  1. code"MODEL_NOT_FOUND"
  2. message"could not find a model with id install"
  3. name"Error"
  4. stack"Error: could not find a model with id install↵ at /workspace/node_modules/loopback/lib/model.js:166:19 [snip]
  5. status404
  6. statusCode404

obivously id install does not exist

the angular sdk has a put url of 
  1. Request URL:
whilst the explorer api has a put url of

  1. Request URL:
so that's where the difference is

What do I need to do to the angular call to make it work properly ?

Thanks

jmls

unread,
Oct 2, 2015, 4:01:38 AM10/2/15
to LoopbackJS
**update#2**

so if I change the method to a get, all works just fine

exchsac

unread,
Aug 11, 2016, 6:35:11 AM8/11/16
to LoopbackJS
You need to supply an empty object as body argument:

"This method does not accept any data. Supply an empty object."

lb-services.js


Reply all
Reply to author
Forward
0 new messages