Skip to content

This setup demonstrates how to access and add metadata in a Nestjs Grpc interceptor as well as sending metadata to the caller/client

Notifications You must be signed in to change notification settings

alfreddohnani/nestjs-grpc-interceptor

Repository files navigation

How to use Interceptors in Nestjs to manipulate gRPC metadata

Installation

yarn install

Running the app

# watch mode
$ yarn run start:dev

Take Note

In the context of NestJS, when working with gRPC, accessing the ServerUnaryCall object directly within an interceptor is not straightforward due to the way NestJS abstracts the gRPC layer. You can only manipulate the metadata in the interceptor. Then, you can access the ServerUnaryCall object in a gRPC controller method and send the metadata as demonstrated in ProductController.

How to test

With PostMan:

  1. Set the url of the request as grpc://localhost:3333.
  2. Import the product.proto file as the service definition.
  3. Choose ProductService/CreateProduct
  4. Copy paste the following payload as the message
{
   "category": "dolor enim ad reprehenderit id",
   "description": "ipsum officia ea aliquip irure",
   "name": "pariatur nulla eu irure",
   "price": 1933868788
}
  • Take note of the metadata tab of the response. You'll see 'Set-Cookie', 'yummy_cookie=choco' metadata which was set in the ProductInterceptor

Open issues if you have further questions.

About

This setup demonstrates how to access and add metadata in a Nestjs Grpc interceptor as well as sending metadata to the caller/client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published