{"id":19165724,"url":"https://github.com/loopbackio/loopback-connector-grpc","last_synced_at":"2025-05-07T12:23:41.568Z","repository":{"id":42659717,"uuid":"76596411","full_name":"loopbackio/loopback-connector-grpc","owner":"loopbackio","description":"LoopBack connector for gRPC (experimental)","archived":false,"fork":false,"pushed_at":"2023-12-15T05:13:21.000Z","size":172,"stargazers_count":16,"open_issues_count":1,"forks_count":2,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-19T18:16:42.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loopbackio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-15T21:11:29.000Z","updated_at":"2021-12-20T02:27:42.000Z","dependencies_parsed_at":"2024-06-21T20:30:54.684Z","dependency_job_id":"8d780499-8e08-4ac9-ba7c-63368ccd1a84","html_url":"https://github.com/loopbackio/loopback-connector-grpc","commit_stats":{"total_commits":34,"total_committers":9,"mean_commits":"3.7777777777777777","dds":0.7352941176470589,"last_synced_commit":"7ade0f680cbf04dea3462d1234a019ebf151fe12"},"previous_names":["strongloop/loopback-connector-grpc"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-grpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-grpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-grpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-grpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loopbackio","download_url":"https://codeload.github.com/loopbackio/loopback-connector-grpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252874757,"owners_count":21817901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T09:29:08.322Z","updated_at":"2025-05-07T12:23:41.544Z","avatar_url":"https://github.com/loopbackio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# loopback-connector-grpc\n\n[![CI](https://github.com/loopbackio/loopback-connector-grpc/actions/workflows/ci.yaml/badge.svg)](https://github.com/loopbackio/loopback-connector-grpc/actions/workflows/ci.yaml)\n[![Build Status](https://app.travis-ci.com/loopbackio/loopback-connector-grpc.svg?branch=master)](https://app.travis-ci.com/loopbackio/loopback-connector-grpc)\n[![Coverage Status](https://coveralls.io/repos/github/loopbackio/loopback-connector-grpc/badge.svg?branch=master)](https://coveralls.io/github/loopbackio/loopback-connector-grpc?branch=master)\n\nThe gRPC connector enables LoopBack applications to interact with [gRPC](http://www.grpc.io/) services.\n\n## Installation \n\nIn your application root directory, enter:\n```\n$ npm install loopback-connector-grpc --save\n```\n\nThis will install the module from npm and add it as a dependency to the application's `package.json` file.\n\n## Configuration\n\nTo interact with a gRPC API, configure a data source backed by the gRPC connector:\n\nWith code:\n\n```javascript\n  var ds = loopback.createDataSource('grpc', {\n    connector: 'loopback-connector-grpc',\n    spec: 'note.proto',\n  });\n```\n\nWith JSON in `datasources.json` (for example, with basic authentication):\n\n```\n\"gRPCDataSource\": {\n    \"name\": \"gRPCDataSource\",\n    \"connector\": \"grpc\",\n    \"spec\": \"note.proto\",\n    \"security\": {\n      \"type\" : \"basic\", \n      \"username\": \"the user name\",\n      \"password\": \"thepassword\"\n}    \n```\n\n## Data source properties\n\nSpecify the options for the data source with the following properties. \n\n| Property | Description | Default   |\n|----------|-------------|-----------|\n| connector | Must be `'loopback-connector-grpc'` to specify gRPC connector| None |\n|spec      | HTTP URL or path to the gRPC specification file (with file name extension `.yaml/.yml` or `.json`).  File path must be relative to current working directory (`process.cwd()`).| None |\n|validate | When `true`, validates provided `spec` against gRPC specification 2.0 before initializing a data source. | `false`|\n| security | Security configuration for making authenticated requests to the API. | None |\n\n### Authentication\n\nBasic authentication:\n\n```javascript\nsecurity: {\n  rootCerts: 'rootCerts.crt', // Path to root certs\n  key: 'gprc.key', // Path to client SSL private key\n  cert: 'grpc.crt' // Path to client SSL certificate\n}\n```\n\n### Creating a model from the gRPC data source\n\nThe gRPC connector loads the API specification document asynchronously. As a result, the data source won't be ready to create models until it is connected.  For best results, use an event handler for the `connected` event of data source:\n\n```javascript\nds.once('connected', function(){\n  var PetService = ds.createModel('PetService', {});\n  ...\n});\n```\nOnce the model is created, all available gRPC API operations can be accessed as model methods, for example:\n\n```javascript\n...\nPetService.getPetById({petId: 1}, function (err, res){\n  ...\n});\n```\n\nThe model methods can also be called as promises:\n\n```javascript\nPetService.getPetById({petId: 1}).then(function(res) {\n  ...\n}, function(err) {\n  ...\n});\n// in async/await flavor\nconst res = await PetService.getPetById({petId: 1});\n```\n\n### Extend a model to wrap/mediate API Operations\nOnce you define the model, you can wrap or mediate it to define new methods. The following example simplifies the `getPetById` operation to a method that takes `petID` and returns a Pet instance.\n\n```javascript\nPetService.searchPet = function(petID, cb){\n  PetService.getPetById({petId: petID}, function(err, res){\n    if(err) cb(err, null);\n    var result = res.data;\n    cb(null, result);\n  });\n};\n```\n\nThis custom method on the `PetService` model can be exposed as REST API end-point. It uses `loopback.remoteMethod` to define the mappings:\n\n```javascript\nPetService.remoteMethod(\n  'searchPet', {\n    accepts: [\n      { arg: 'petID', type: 'string', required: true,\n        http: { source: 'query' }\n      }\n    ],\n    returns: {arg: 'result', type: 'object', root: true },\n    http: {verb: 'get', path: '/searchPet'}\n  }\n);\n```\n\n### Example\n\nComing soon...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopbackio%2Floopback-connector-grpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floopbackio%2Floopback-connector-grpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopbackio%2Floopback-connector-grpc/lists"}