Registry / integration / loopback-connector-rest

loopback-connector-rest

JSON →
library6.0.7jsnpmunverified

The LoopBack REST Connector (v6.0.7) enables LoopBack applications to interact with third-party REST APIs using a template-driven approach. It supports both resource operations and custom methods defined via templates. Current stable version is 6.0.7, supporting Node.js >=20. Key differentiators include integration with LoopBack 4's service and controller layers, template-based API mapping, and response path extraction. Compared to generic HTTP clients, it provides declarative datasource configuration and automatic CRUD mapping for REST endpoints.

npm install loopback-connector-rest
INSTALL
IMPORT
SIG · LOOPBACK-CONNECTOR
L
loopback-connector-rest
integrationjavascriptv6.0.7
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.

RestConnector
import { RestConnector } from 'loopback-connector-rest';
const RestConnector = require('loopback-connector-rest');
Uses named export for TypeScript/ESM. For CommonJS, use require with .default or use named export pattern.
RestServiceMixin
import { RestServiceMixin } from 'loopback-connector-rest';
import { RestService } from 'loopback-connector-rest';
RestServiceMixin is the correct symbol for mixing into LoopBack services. Common mistake is using wrong mixin name.
restConnector
import * as connector from 'loopback-connector-rest'; const restConnector = connector.default;
import restConnector from 'loopback-connector-rest';
Default export is deprecated; use named exports. For ESM, import as namespace and access default property.
DataSource
import { DataSource } from 'loopback-datasource-juggler'; const ds = new DataSource('rest', connector);
const ds = new DataSource(require('loopback-connector-rest'));
DataSource comes from loopback-datasource-juggler, not from the connector package. Pass the connector instance as second argument.

Configures a LoopBack REST datasource with a Google Geocoding template and calls the geocode function. Demonstrates datasource setup, template definition with response path extraction, and async invocation.

import { DataSource } from 'loopback-datasource-juggler'; import { RestConnector } from 'loopback-connector-rest'; // Define a REST datasource with a Google Geocoding operation const ds = new DataSource('rest', { connector: 'rest', debug: false, options: { headers: { accept: 'application/json', 'content-type': 'application/json' }, strictSSL: process.env.NODE_ENV !== 'development' }, operations: [{ template: { method: 'GET', url: 'https://maps.googleapis.com/maps/api/geocode/json', query: { address: '{address}', key: process.env.GOOGLE_API_KEY ?? '' }, responsePath: '$.results[0].geometry.location' }, functions: { geocode: ['address'] } }] }); // Use the datasource in a model or service ds.on('connected', async () => { const result = await ds.operations.geocode('1600 Amphitheatre Parkway, Mountain View, CA'); console.log(result); // { lat: 37.4224764, lng: -122.0842499 } });
Debug
Known issues
breakingloopback-connector-rest v6 drops support for Node.js <20 and LoopBack 3.x datasource configuration.
fix
Upgrade to Node.js >=20 and migrate to LoopBack 4 service/repository pattern.
affects: >=6.0.0
deprecatedThe 'request' module used as HTTP client is deprecated and may be removed in future releases.
fix
Consider using REST connector with 'axios' or native fetch by overriding the request module, or migrate to loopback-connector-openapi.
affects: all
gotchaDefault export is deprecated in v6; imports must use named exports.
fix
Use `import { RestConnector } from 'loopback-connector-rest';` instead of default import.
affects: >=6.0.0
gotchaResponse path '$' vs 'response.path' confusion. JSONPath expressions use '$' for root, but users often provide plain property paths.
fix
Always prefix JSONPath expressions with '$.' (e.g., '$.results[0]' not 'results[0]').
affects: all
deprecatedLoopBack 3 styled resource operations (find, create, etc.) are deprecated in LoopBack 4 and may not work with this connector.
fix
Use custom template operations or migrate to LoopBack 4 service layer with REST datasource proxying.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'results')
Response from REST API does not match the expected JSONPath structure defined in 'responsePath'.
fix
Log the raw response (set debug: true) and adjust the responsePath to match the actual JSON structure.
Error: connect ECONNREFUSED <host>:<port>
REST endpoint is unreachable due to network issues, wrong URL, or firewall blocking.
fix
Verify the URL is correct and accessible from the Node.js environment. Check network proxy settings if behind a corporate firewall.
Error: self signed certificate in certificate chain
The REST API uses a self-signed SSL certificate, and strictSSL is set to true (default).
fix
Set 'strictSSL': false in the datasource options or operation template options, but only for development/trusted APIs.
Error: Invalid template: method must be a string, got undefined
Template method is missing or incorrectly specified (not a string). Common mistake: using lowercase 'get' instead of uppercase 'GET'.
fix
Ensure template.method is one of 'GET', 'POST', 'PUT', 'DELETE', 'PATCH' (uppercase). Example: "method": "GET"
Upgrade
Version history
6.0.7latest on npm
Audit
Dependencies
requestrequiredUsed as the underlying HTTP client for all REST requests. Deprecated in favor of alternatives in newer versions.
Agent activity
44 hits · last 30 days
node
38
Resources
loopback-connector-rest — npm install loopback-connector-rest · libregistry