Loopback rest connector

901 views
Skip to first unread message

Megha Honna

unread,
Sep 8, 2014, 5:38:20 AM9/8/14
to loopb...@googlegroups.com
Hi,

I am newbie trying loopback rest connector, i have created datasource using rest connector and attached it to model.
 My requirement is to expose api which consumes the response i get from enterprise rest api. can somebody guide me to small example. 

Also all the files in boot folder get the app(loopback) instance. what type of instance do the files in common/models/ js files get?

TIA
Regards,
Megha

Raymond Feng

unread,
Sep 8, 2014, 12:11:29 PM9/8/14
to Megha Honna, loopb...@googlegroups.com
You should be able to find a sample usage of REST connector at https://github.com/strongloop/loopback-example-app.


Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Ni

unread,
Apr 8, 2015, 6:23:58 PM4/8/15
to loopb...@googlegroups.com
Hello,

I see in the example suggested, a rest datasource using rest connector is called within a remoteMethod nearby.

I am looking to do something different.

I am looking to either in 
/common/some_rest_service
or
/server/some_rest_service
have a bunch of model files  using the rest connector as an endpoint.  Basically I want to make a rest client within the model layer, NOT the rest api layer.

so my questions are,
suppose I have /common/models/myloopbackmodel.js
however in the "some_rest_service", there is also a model nammed myloopbackmodel

so I want to have 
/common/models/myloopbackmodel.js (PersistentModel using mongodb datasource)
AND
/common/some_rest_service/myloopbackmodel.js (  ??  using rest datasource)

1.) How can I have app.models basically have a namespace for this?

2.) would the object inside model-config.json have to contain both and have unique name?
  "myloopbackmodel": {
    "dataSource": "mongodb",
    "public": false
  },
  "myloopbackmodel": {
    "dataSource": "some_rest_service",
    "public": true
  },

Raymond Feng

unread,
Apr 8, 2015, 6:37:49 PM4/8/15
to Michael Ni, loopb...@googlegroups.com
We don’t have the namespace support for loopback models yet. You’ll need to choose a unique name for each model.

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

Michael Ni

unread,
Apr 8, 2015, 6:45:27 PM4/8/15
to loopb...@googlegroups.com, micha...@gmail.com
Thanks for the reply Raymond, 

In the example location was a persisted model.
It had a remoteMethod "nearby", that used geo from the rest datasource.

Assume I have a unique name for a model, 

Instead of using persisted model like location, I want to use a "type" like remote rest.  And the model just represents the external rest endpoint.

Michael Ni

unread,
Apr 9, 2015, 7:26:46 PM4/9/15
to loopb...@googlegroups.com, micha...@gmail.com
Ok after getting in contact with a strongloop employee, I have learned:

The loopback REST, and SOAP, connector do not work like the other connectors.  You access them as data sources in code and not connected a models.  There is a future plan for them to work with models, but that is not the case today.

Barbara Force

unread,
Jul 23, 2015, 10:32:14 PM7/23/15
to LoopbackJS, micha...@gmail.com
Do you have sample code on how you used it?

Sachin Dixit

unread,
Aug 30, 2016, 5:26:44 AM8/30/16
to LoopbackJS, micha...@gmail.com
Does that mean if i have client/ModelA/ModelB which maps to server/ModelA/ModelB , i have to make specific calls in both the client modelA and ModelB as if it was an individual connection between one client model to one server model and the nesting will not be supported ?

Which also brings one more question , suppose server introduces server/ModelA/ModelB/ModelC then i have to again manually code the data fetch operation in my new-client model , ModelC  ,because it will not transparently connect ?

Prashant Bhadauria

unread,
Oct 4, 2016, 1:33:00 AM10/4/16
to LoopbackJS, micha...@gmail.com
Hi Sachin,

Try using Loopback Flexirest (https://www.npmjs.com/package/loopback-connector-flexirest). We have been using loopback over commerce server and other enterprise APIs. With flexirest, you can define transformations to convert your server Models to your loopback specified Model. Would be happy to hear any feedback you have.
Reply all
Reply to author
Forward
0 new messages