From fe0a7175f91ea834425ebb52ae659b437b045769 Mon Sep 17 00:00:00 2001 From: Rick Blalock Date: Wed, 3 Aug 2016 16:20:50 -0400 Subject: [PATCH] Update README.md --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 923540b..85d226d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,38 @@ # loopback-connector-remote Remote REST API connector for [loopback-datasource-juggler](https://github.com/strongloop/loopback-datasource-juggler). + +## 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" + } +``` +Note that you should add a `url` property to point to another remote service. +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. + +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`, +the connector will automatically generate the following: + +`app.datasources.MyMicroService.models.foo.bar()` + +### Access it in any model file +To access the remote Loopback service in a model: + +```javascript +module.exports = function(Message) { + + Message.test = function (cb) { + Message.app.datasources.MyMicroService.models.SomeModel.remoteMethodNameHere(function () {}); + + cb(null, {}); + }; + +}; +```