{"id":48421,"library":"loopback-connector-rest","title":"LoopBack REST Connector","description":"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.","status":"active","version":"6.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/loopbackio/loopback-connector-rest","tags":["javascript","LoopBack","REST","DataSource","Connector"],"install":[{"cmd":"npm install loopback-connector-rest","lang":"bash","label":"npm"},{"cmd":"yarn add loopback-connector-rest","lang":"bash","label":"yarn"},{"cmd":"pnpm add loopback-connector-rest","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used as the underlying HTTP client for all REST requests. Deprecated in favor of alternatives in newer versions.","package":"request","optional":false}],"imports":[{"note":"Uses named export for TypeScript/ESM. For CommonJS, use require with .default or use named export pattern.","wrong":"const RestConnector = require('loopback-connector-rest');","symbol":"RestConnector","correct":"import { RestConnector } from 'loopback-connector-rest';"},{"note":"RestServiceMixin is the correct symbol for mixing into LoopBack services. Common mistake is using wrong mixin name.","wrong":"import { RestService } from 'loopback-connector-rest';","symbol":"RestServiceMixin","correct":"import { RestServiceMixin } from 'loopback-connector-rest';"},{"note":"Default export is deprecated; use named exports. For ESM, import as namespace and access default property.","wrong":"import restConnector from 'loopback-connector-rest';","symbol":"restConnector","correct":"import * as connector from 'loopback-connector-rest'; const restConnector = connector.default;"},{"note":"DataSource comes from loopback-datasource-juggler, not from the connector package. Pass the connector instance as second argument.","wrong":"const ds = new DataSource(require('loopback-connector-rest'));","symbol":"DataSource","correct":"import { DataSource } from 'loopback-datasource-juggler';\nconst ds = new DataSource('rest', connector);"}],"quickstart":{"code":"import { DataSource } from 'loopback-datasource-juggler';\nimport { RestConnector } from 'loopback-connector-rest';\n\n// Define a REST datasource with a Google Geocoding operation\nconst ds = new DataSource('rest', {\n  connector: 'rest',\n  debug: false,\n  options: {\n    headers: {\n      accept: 'application/json',\n      'content-type': 'application/json'\n    },\n    strictSSL: process.env.NODE_ENV !== 'development'\n  },\n  operations: [{\n    template: {\n      method: 'GET',\n      url: 'https://maps.googleapis.com/maps/api/geocode/json',\n      query: {\n        address: '{address}',\n        key: process.env.GOOGLE_API_KEY ?? ''\n      },\n      responsePath: '$.results[0].geometry.location'\n    },\n    functions: {\n      geocode: ['address']\n    }\n  }]\n});\n\n// Use the datasource in a model or service\nds.on('connected', async () => {\n  const result = await ds.operations.geocode('1600 Amphitheatre Parkway, Mountain View, CA');\n  console.log(result); // { lat: 37.4224764, lng: -122.0842499 }\n});","lang":"typescript","description":"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."},"warnings":[{"fix":"Upgrade to Node.js >=20 and migrate to LoopBack 4 service/repository pattern.","message":"loopback-connector-rest v6 drops support for Node.js <20 and LoopBack 3.x datasource configuration.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Consider using REST connector with 'axios' or native fetch by overriding the request module, or migrate to loopback-connector-openapi.","message":"The 'request' module used as HTTP client is deprecated and may be removed in future releases.","severity":"deprecated","affected_versions":"all"},{"fix":"Use `import { RestConnector } from 'loopback-connector-rest';` instead of default import.","message":"Default export is deprecated in v6; imports must use named exports.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Always prefix JSONPath expressions with '$.' (e.g., '$.results[0]' not 'results[0]').","message":"Response path '$' vs 'response.path' confusion. JSONPath expressions use '$' for root, but users often provide plain property paths.","severity":"gotcha","affected_versions":"all"},{"fix":"Use custom template operations or migrate to LoopBack 4 service layer with REST datasource proxying.","message":"LoopBack 3 styled resource operations (find, create, etc.) are deprecated in LoopBack 4 and may not work with this connector.","severity":"deprecated","affected_versions":">=5.0.0"}],"env_vars":null,"search_vec":"'20':44 '4':51 '6.0.7':41 'api':19,60 'applic':11 'approach':25 'automat':77 'base':59 'client':70 'compar':66 'configur':75 'connector':3,7,87 'control':55 'crud':78 'current':37 'custom':32 'datasourc':74,86 'declar':73 'defin':34 'differenti':46 'driven':24 'enabl':9 'endpoint':82 'extract':65 'generic':68 'http':69 'includ':47 'integr':48 'interact':13 'javascript':83 'key':45 'layer':56 'loopback':1,5,10,50,84 'map':61,79 'method':33 'node.js':43 'oper':30 'parti':17 'path':64 'provid':72 'resourc':29 'respons':63 'rest':2,6,18,81,85 'servic':53 'stabl':38 'support':27,42 'templat':23,36,58 'template-bas':57 'template-driven':22 'third':16 'third-parti':15 'use':20 'v6.0.7':8 'version':39 'via':35","created_at":"2026-06-07T16:56:34.028618+00:00","updated_at":"2026-06-07T16:56:34.028618+00:00","problems":[{"fix":"Log the raw response (set debug: true) and adjust the responsePath to match the actual JSON structure.","cause":"Response from REST API does not match the expected JSONPath structure defined in 'responsePath'.","error":"TypeError: Cannot read properties of undefined (reading 'results')"},{"fix":"Verify the URL is correct and accessible from the Node.js environment. Check network proxy settings if behind a corporate firewall.","cause":"REST endpoint is unreachable due to network issues, wrong URL, or firewall blocking.","error":"Error: connect ECONNREFUSED <host>:<port>"},{"fix":"Set 'strictSSL': false in the datasource options or operation template options, but only for development/trusted APIs.","cause":"The REST API uses a self-signed SSL certificate, and strictSSL is set to true (default).","error":"Error: self signed certificate in certificate chain"},{"fix":"Ensure template.method is one of 'GET', 'POST', 'PUT', 'DELETE', 'PATCH' (uppercase). Example: \"method\": \"GET\"","cause":"Template method is missing or incorrectly specified (not a string). Common mistake: using lowercase 'get' instead of uppercase 'GET'.","error":"Error: Invalid template: method must be a string, got undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/loopbackio/loopback-connector-rest#readme","github":"https://github.com/loopbackio/loopback-connector-rest","docs":null,"changelog":null,"pypi":null,"npm":"loopback-connector-rest","openapi_spec":null,"status_page":null,"smithery":null,"categories":["integration"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}