npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

loopback-connector-remote

v3.4.1

Published

Remote REST API connector for Loopback

Downloads

90,041

Readme

loopback-connector-remote

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

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
}