Registry / devops / loopback-connector-remote

loopback-connector-remote

JSON →
library3.4.1jsnpmunverified

The remote connector enables using a LoopBack application as a data source via REST, allowing seamless integration of remote APIs into LoopBack models. Current stable version is 3.4.1, supporting Node >=6. It is part of the LoopBack ecosystem and is maintained with irregular releases. Differentiators: automatic generation of client-side models from remote service endpoints, supports both server and browser environments, and abstracts REST calls via StrongRemoting. Alternative to manual HTTP requests.

npm install loopback-connector-remote
INSTALL
IMPORT
SIG · LOOPBACK-CONNECTOR
L
loopback-connector-remote
devopsjavascriptv3.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DataSource
import { DataSource } from 'loopback-datasource-juggler';
const DataSource = require('loopback-datasource-juggler').DataSource;
The remote connector is used via loopback-datasource-juggler; it is not directly imported. The DataSource constructor takes the connector name 'remote'.
remoteConnector
import { DataSource } from 'loopback-datasource-juggler'; const ds = new DataSource('remote', { url: 'http://localhost:3000/api' });
const ds = new DataSource('loopback-connector-remote', { ... });
Connector name is 'remote', not the full package name. Do not include 'loopback-connector-' prefix.
model methods
const MyModel = ds.models.MyModel; MyModel.methodName(params, callback);
MyModel.methodName(params, (err, data) => { console.log(data); }); // callback style is incorrect; use promise or callback as defined
Models are generated automatically from the remote API. Methods return promises if the remote method supports promises, otherwise callbacks.

Shows how to create a remote data source and call a remote method using the LoopBack remote connector.

import { DataSource } from 'loopback-datasource-juggler'; const ds = new DataSource('remote', { url: 'http://localhost:3000/api', // Optional: host, port, root instead of url }); // Models are automatically generated based on the remote API const RemoteModel = ds.models['SomeModel']; // Replace with actual model name // Call a remote method (assumes 'greet' is a remote method) RemoteModel.greet({ name: 'World' }, (err, result) => { if (err) console.error(err); else console.log(result); }); // Or use promises (if strong-remoting version supports it) RemoteModel.greet({ name: 'World' }) .then(result => console.log(result)) .catch(err => console.error(err));
Debug
Known issues
gotchaAuthentication credentials must be configured programmatically, not via datasource JSON. See issue #3.
fix
Add code to set credentials: app.dataSources.remote.connector.remotes.auth = { bearer: Buffer.from(token).toString('base64'), sendImmediately: true };
affects: >=3.0
deprecatedLoopBack v2 compatible versions of this connector are deprecated. Use v3.x with LoopBack v3+.
fix
Upgrade to loopback-connector-remote@3 and use LoopBack v3+.
affects: <3.0
gotchaWhen using this connector with the MongoDB connector on the server, model methods may not be fully replicated on the client. Ensure client-side models are correctly defined using the 'MyModel' pattern.
fix
Explicitly define client-side model stubs using the `use` pattern: app.model(MyModel, { dataSource: 'remote' });
affects: >=3.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED 127.0.0.1:3000
The remote LoopBack API server is not running or the URL is incorrect.
fix
Ensure the remote server is started and that the `url` property in datasources.json points to the correct endpoint.
TypeError: Cannot read property 'SomeModel' of undefined
The remote server has not exposed any models, or the datasource has not fully initialized.
fix
Check that the remote API exposes models and that the datasource is properly connected. Use ds.on('connected', callback) to wait for initialization.
Error: 401 Unauthorized - Missing Authorization header
Remote API requires authentication but credentials are not configured.
fix
Set authentication token programmatically: app.dataSources.remote.connector.remotes.auth = { bearer: Buffer.from(token).toString('base64'), sendImmediately: true };
Upgrade
Version history
3.4.1latest on npm
Audit
Dependencies
strong-remotingrequiredCore dependency for remote communication (REST/JSON marshalling). Required at runtime.
loopback-datasource-juggleroptionalLoopBack ORM and data source abstraction layer. Required for model integration.
Agent activity
7 hits · last 30 days
node
6
Resources
loopback-connector-remote — npm install loopback-connector-remote · libregistry