{"id":16403696,"url":"https://github.com/coderdiaz/nestjs-grpc-transport","last_synced_at":"2025-02-23T17:27:23.756Z","repository":{"id":107872917,"uuid":"125299146","full_name":"coderdiaz/nestjs-grpc-transport","owner":"coderdiaz","description":"GRPC transport layer for the NestJS framework","archived":false,"fork":false,"pushed_at":"2018-03-15T03:42:56.000Z","size":110,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-05T08:29:29.849Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coderdiaz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-15T02:05:01.000Z","updated_at":"2021-12-07T13:47:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"72a2cc40-654d-44d8-af89-11409b071a41","html_url":"https://github.com/coderdiaz/nestjs-grpc-transport","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderdiaz%2Fnestjs-grpc-transport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderdiaz%2Fnestjs-grpc-transport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderdiaz%2Fnestjs-grpc-transport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderdiaz%2Fnestjs-grpc-transport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderdiaz","download_url":"https://codeload.github.com/coderdiaz/nestjs-grpc-transport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240350283,"owners_count":19787640,"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-10-11T05:50:04.257Z","updated_at":"2025-02-23T17:27:23.724Z","avatar_url":"https://github.com/coderdiaz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nestjs-grpc-transport\n\n[![CircleCI](https://circleci.com/gh/fresh8/nestjs-grpc-transport.svg?style=svg)](https://circleci.com/gh/fresh8/nestjs-grpc-transport)\n[![Coverage Status](https://coveralls.io/repos/github/fresh8/nestjs-grpc-transport/badge.svg?branch=master)](https://coveralls.io/github/fresh8/nestjs-grpc-transport?branch=master)\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n\n[GRPC](https://grpc.io) transport layer for the [NestJS](https://github.com/kamilmysliwiec/nest) framework.\n\n## Requirements\n- Typescript 2.x\n- Node boron\n- Npm 5.x\n- NestJS v3.0.1 (there is breaking change in v3.1.1).\n\n## Installation\n```npm install @fresh8/nestjs-grpc-transport --save```\n\n## Quickstart\n\nCreate your protobuf definition `sample.proto`:\n\n```protobuf\nsyntax = \"proto3\";\n\npackage sample;\n\nservice Greeter {\n  rpc SayHello (HelloRequest) returns (HelloReply) {}\n}\n\nmessage HelloRequest {\n  string name = 1;\n}\n\nmessage HelloReply {\n  string message = 1;\n}\n```\n\nGenerate your Typescript interfaces using [rxjs-grpc](https://github.com/kondi/rxjs-grpc/blob/master/README.md#quickstart).\n```\n./node_modules/.bin/rxjs-grpc -o grpc-namespaces.ts *.proto\n```\n\nCreate your first controller. The `@rpc` decorator provides some metadata needed by Nest, and takes care of providing an [Observable](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html) for [rxjs-grpc](https://github.com/kondi/rxjs-grpc/blob/master/README.md#quickstart).\n\n```typescript\nimport { Controller } from '@nestjs/common'\nimport { rpc } from '@fresh8/nestjs-grpc-transport'\n\nimport { sample } from './grpc-namespaces'\n\n@Controller()\nexport default class TestController {\n  /**\n   * sayHello RPC method\n   */\n  @rpc\n  async sayHello(request: sample.HelloRequest): Promise\u003csample.HelloReply\u003e {\n    const res = await this.someAsyncThing()\n    return { message: `Hello ${request.name}: ${res}` }\n  }\n  \n  /**\n   * Some dummy async method. This might be a call to a database in\n   * a proper application.\n   */\n  someAsyncThing() {\n    return Promise.resolve(`:)`)\n  }\n}\n\n```\n\nCreate your [GRPC](https://grpc.io) server and provide it to your [NestJS](https://github.com/kamilmysliwiec/nest) application.\n\n```typescript\nimport { Module } from '@nestjs/common'\nimport { NestFactory } from '@nestjs/core'\nimport { createServer } from '@fresh8/nestjs-grpc-transport'\n\nimport { sample } from './grpc-namespaces'\nimport { TestController } from './test-controller'\n\n/**\n * Example application\n */\n@Module({\n  controllers: [TestController]\n})\nexport class ApplicationModule {}\n\n/**\n * Create a nest application that runs over GRPC.\n */\nconst app = NestFactory.createMicroservice(ApplicationModule, {\n  strategy: createServer\u003csample.ServerBuilder\u003e({\n    host: '0.0.0.0',\n    port: 50051,\n    protoPath: `path/to/sample.proto`,\n    packageName: 'sample',\n    serviceName: 'Greeter'\n  })\n})\n\n/**\n * Start your app as normal.\n */\napp.listen(() =\u003e {\n  console.log('GRPC server running on 0.0.0.0:50051')\n})\n```\n\n## Examples\nA simple example project is provided [here](example).\n\n## A note on Exceptions handling\nNestjs itself catches and handles exceptions as part of its [Exception Filters](https://docs.nestjs.com/microservices/exception-filters) feature. `nestjs-grpc-transport` only transforms it to the format expected by `rxjs-grpc`.\n\nTo the best of our understanding this implies:\n - [Any exception](https://stackoverflow.com/questions/47756819/shared-exceptions-between-http-and-rpc) that is not an instance of `@nestjs/microservices/RpcException` will be reported as `Internal` error (code 13).\n - To send errors other than `Internal` simply throw a new RpcException with the following property:\n   - `code : number`:  The [exception code](https://godoc.org/google.golang.org/grpc/codes#Code). Defaults to `13`.\n   - `message : string`: An additional message. Defaults to \"Internal Server Error\"\n - Exceptions [are not logged](https://github.com/nestjs/nest/issues/303).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderdiaz%2Fnestjs-grpc-transport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderdiaz%2Fnestjs-grpc-transport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderdiaz%2Fnestjs-grpc-transport/lists"}