0

Trying to use loopback framework for simulating a backend service. I need to retrieve an object using POST method. I know REST services typically allow POST to update/create a resource, but here, I cannot use GET with resource details for retrieving data.

In my case, POST data contains a few query fields that have to be used to query an object and send json back. Is this possible with loopback? I cannot use GET with query parms due to security restrictions with sending data as query parms in a GET URL.

here is post request data

[ { customer:"sam", city:"noWhere", } ]

the POST event should query by customer and city, then return matching customer object

[ { customer:"sam", postcode:"352345", city:"noWhere", country:"US" } ]
Serg
  • 2,346
  • 3
  • 29
  • 38
Mogalt
  • 11
  • 2
  • You can override built-in methods. Just read the documentation at http://docs.strongloop.com/display/public/LB/Customizing+models, in the section 'Change the implementation of built-in methods '. – Anuj Verma Apr 07 '15 at 04:10

2 Answers2

0

I think that what you need is an express http method override middleware: https://github.com/expressjs/method-override

And defining middleware in loopback: http://docs.strongloop.com/display/LB/Defining+middleware

Alex V
  • 1,155
  • 8
  • 10
0

You can override default loopback endpoint, like this

// Define custom remote method
Customer.fetch = function(oRequest, fnResponseCb) {
  /* Do staff to find customer and finally call fnResponseCb(null, oCustomer) */
}

// Override custom remote method
Customer.remoteMethod('fetch', {
  accepts: {
    arg: 'oRequest',
    type: 'object',
    http: { source: 'body' }
  },
  returns: {
    type: 'object',
    root: true
  },
  http: {
    path: '/',
    verb: 'POST'
  },
  description : 'Fetch Customer'
});
IvanZh
  • 2,265
  • 1
  • 18
  • 26