Giter Site home page Giter Site logo

vestigegroup / loopback-connector-remote Goto Github PK

View Code? Open in Web Editor NEW

This project forked from strongloop/loopback-connector-remote

1.0 1.0 0.0 153 KB

LoopBack remote REST API connector

Home Page: http://loopback.io/doc/en/lb2/Remote-connector.html

License: Other

JavaScript 100.00%

loopback-connector-remote's Introduction

loopback-connector-remote

THIS CONNECTOR DOES NOT SUPPORT LOOPBACK 4

โš ๏ธ LoopBack 3 has reached end of life. We are no longer accepting pull requests or providing support for community users. The only exception is fixes for critical bugs and security vulnerabilities provided as part of support for IBM API Connect customers. We urge all LoopBack 3 users to migrate their applications to LoopBack 4 as soon as possible. Learn more about LoopBack's long term support policy.

The remote connector enables you to use a LoopBack application as a data source via REST. You can use the remote connector with a LoopBack application, a Node application, or a browser-based application that uses LoopBack in the client. The connector uses Strong Remoting.

In general, using the remote connector is more convenient than calling into REST API, and enables you to switch the transport later if you need to.

Use loopback-connector-remote:

  • Version 3.x with LoopBack v3 and later.
  • Prior versions with LoopBack v2.

Installation

In your application root directory, enter:

$ npm install loopback-connector-remote --save

This will install the module and add it as a dependency to the application's package.json file.

Creating a remote data source

Create a new remote data source with the datasource generator:

$ lb datasource

When prompted:

  • For connector, scroll down and select other.
  • For connector name without the loopback-connector- prefix, enter remote.

This creates an entry in datasources.json; Then you need to edit this to add the data source properties, for example:

{% include code-caption.html content="/server/datasources.json" %}

...
 "myRemoteDataSource": {
    "name": "myRemoteDataSource",
    "connector": "remote",
    "url": "http://localhost:3000/api"
  }
 ...

The url property specifies the root URL of the LoopBack API. 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 myRemoteDataSource 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 the model foo exposes a remote method called bar, the connector will automatically generate the following:

app.datasources.myRemoteDataSource.models.foo.bar()

Access it in any model file

To access the remote Loopback service in a model:

module.exports = function(Message) {

  Message.test = function (cb) {
    Message.app.datasources.myRemoteDataSource.models.
      SomeModel.remoteMethodNameHere(function () {});

    cb(null, {});
  };

};

Remote data source properties

Property Type Description
host String Hostname of LoopBack application providing remote data source.
port Number Port number of LoopBack application providing remote data source.
root String Path to API root of LoopBack application providing remote data source.
url String Full URL of LoopBack application providing remote connector. Use instead of host, port, and root properties.

Configuring authentication

The remote connector does not support JSON-based configuration of the authentication credentials (see issue #3). You can use the following code as a workaround. It assumes that your data source is called "remote" and the AccessToken id is provided in the variable "token".

app.dataSources.remote.connector.remotes.auth = {
  bearer: new Buffer(token).toString('base64'),
  sendImmediately: true
};

Using with MongoDB connector

When using the MongoDB connector on the server and a remote connector on the client, use the following id property:

"id": {
  "type": "string",
  "generated": true,
  "id": true
}

loopback-connector-remote's People

Contributors

bajtos avatar kraman avatar superkhau avatar rmg avatar dhmlau avatar nabdelgadir avatar virkt25 avatar glesage avatar ritch avatar siddhipai avatar simonhoibm avatar angfal avatar amir-61 avatar sam-github avatar richardpringle avatar agnes512 avatar mitsos1os avatar joetjengerdes avatar traksewt avatar rblalock avatar srcrawford avatar crandmck avatar

Stargazers

Harish Vagjiyani avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.