Skip to content

nersent/grpc-nest

Repository files navigation

☁️ grpc-nest

Type-safe thin wraper around grpc-js for Nest.js with support for promises.

Note: This library is in an early development stage. Expect breaking changes.

Installation

yarn add @nersent/grpc-nest

Quick Start

1. Compile proto

yarn grpc-nest ./example/*.proto ./example/generated

2.

index.ts

import { createGrpcTransport } from '@nersent/grpc-nest'; 

const app = await NestFactory.create(AppModule);

app.connectMicroservice<MicroserviceOptions>(
  createGrpcTransport({ address: "0.0.0.0:4269" }, app),
);

await app.startAllMicroservices();

app_module.ts

import { GrpcModule } from '@nersent/grpc-nest';

@Module({
  imports: [GrpcModule],
  controllers: [ApiController]
})
export class AppModule {}

api_controller.ts

import {
  IExampleApiService,
  ExampleApiService,
} from "./generated/example_grpc_pb";
import {
  ExampleApiStatusRequest,
  ExampleApiStatusResponse,
} from "./generated/example_pb";

@GrpcController(ExampleApiService)
export class ApiController implements IGrpcController<IExampleApiService> {
  public async status(
    req: ExampleApiStatusRequest,
  ): Promise<ExampleApiStatusResponse> {
    const name = req.getName();
    const res = new ExampleApiStatusResponse();
    res.setMessage(name);
    return res;
  }
}

Made by Nersent

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published