Calling the Loopback post method

I want to send a post request with a loopback "invokeStaticMethod". Please help me how to do this. I want to send a POST API request to the address below:

localhost: 3000 / api / user / id / unblock With parameter {"userId", "blockId"}

Please let me know how can I send a POST request using Loopback

0


source to share


1 answer


I believe this is what you are looking for ...

https://loopback.io/doc/en/lb3/Adding-remote-methods-to-built-in-models.html



In your case, it should look something like this ...

module.exports = function(app) {
  const User = app.models.User;

  User.unblock = function(userId, blockId, cb) {
      ... <Your logic goes here> ...
      cb(null, result);
  };

  User.remoteMethod('unblock', {
      accepts: [{arg: 'userId', type: 'string'}, {arg: 'blockId', type: 'string'}],
      returns: {arg: 'result', type: 'string'}
  });

      

-2


source







All Articles