loopback-connector-remote/README.md

42 lines
1.4 KiB
Markdown
Raw Normal View History

2016-01-22 21:39:13 +00:00
# loopback-connector-remote
2014-09-25 21:06:06 +00:00
2016-01-22 21:40:18 +00:00
Remote REST API connector for [loopback-datasource-juggler](https://github.com/strongloop/loopback-datasource-juggler).
2016-08-03 20:20:50 +00:00
2016-09-01 07:39:02 +00:00
- The version range 2.x is compatible with LoopBack v3 and newer.
- Use the older range 1.x for applications using LoopBack v2.
2016-08-03 20:20:50 +00:00
## Quick Explanation
Use this connector to create a datasource from another Loopback application. Below is a quick example:
### datasource.json
```json
"MyMicroService": {
"name": "MyMicroService",
"connector": "remote"
}
```
2016-09-01 07:39:02 +00:00
Note that you should add a `url` property to point to another remote service.
2016-08-03 20:20:50 +00:00
If you do not specify a `url` property, the remote connector will point to it's own host name, port it's running on, etc.
2016-09-01 07:39:02 +00:00
The connector will generate models on the MyMicroService datasource object based on the models/methods exposed from the remote service. Those models will have methods attached that are
from the model's remote methods. So if you exposed a remote method from that micro-service called `bar` from the model `foo`,
2016-08-03 20:20:50 +00:00
the connector will automatically generate the following:
`app.datasources.MyMicroService.models.foo.bar()`
### Access it in any model file
2016-09-01 07:39:02 +00:00
To access the remote Loopback service in a model:
2016-08-03 20:20:50 +00:00
```javascript
module.exports = function(Message) {
Message.test = function (cb) {
Message.app.datasources.MyMicroService.models.SomeModel.remoteMethodNameHere(function () {});
2016-09-01 07:39:02 +00:00
2016-08-03 20:20:50 +00:00
cb(null, {});
};
2016-09-01 07:39:02 +00:00
2016-08-03 20:20:50 +00:00
};
```