Enabling gRPC server reflection
Tags: aspcore, grpc, uncategorized, web
Published: 2022-12-13 15:37:48

---
title: Enabling gRPC server reflection
published: true
date: 2022-12-13 14:39:11 UTC
tags: AspCore,gRPC,Uncategorized,Web
canonical_url: https://irina.codes/enabling-grpc-server-reflection/
---

 ![enable grpc server reflection and use it with postman](https://irina.codes/wp-content/uploads/2022/12/Articole-800-%C3%97-450-px.png)

Enabling gRPC server reflection will allow you to easily call your gRPC services from [Postman](https://www.postman.com/) without actually loading the protofile .

PostMan will help you test your gRPC services, by giving you the same look and feel as a you would have with a traditional HTTP API.

gRPC uses binary serialization, which means that is not human readable as JSON is. Is still possible to use grpcurl or similar tools, but you will not be able to decipher binary. Having the right tools will help you understand gRPC faster, because it has a slightly different vocabulary.

When you open PostMan and click the New button , you can choose to issue gRPC requests. Thankfully, this is not in beta anymore.

![](https://irina.codes/wp-content/uploads/2022/12/image-1024x650.png)
_PostMan New menu options_

To issue a gRPC request, you will need to specify the URL of the server (as you would do with a regular RESTful API), and then give PostMan access to the proto file that is implemented on the server. In this case, you need to help the tool a bit, so you can gain access to available functionality.

To do that you can simply import the proto file or let PostMan discover what is available.

In this case we will use the second option, because we would want our service operations to be somehow discoverable.

![](https://irina.codes/wp-content/uploads/2022/12/image-2-1024x465.png)
_Different ways of ‘accessing’ the proto file contract_

Now, if we try to click the highlighted option, we will get a big red error. This is as if our server throws an Unimplemented exception from a method.

![](https://irina.codes/wp-content/uploads/2022/12/image-4.png)

In reality, if we look at the logs, it actually does throw that kind of exception. ![🙂](https://s.w.org/images/core/emoji/14.0.0/72x72/1f642.png)

```
info: Grpc.AspNetCore.Server.Internal.ServerCallHandlerFactory[1]
      Service 'grpc.reflection.v1alpha.ServerReflection' is unimplemented.
```

Enabling gRPC server reflection requires a few code tweaks because we actually need to an implementation that allows reflection over our grPC services.

First, install `Grpc.AspNetCore.Server.Reflection` NuGet package. This will contain the ServerReflection implementation that will we need, that allows external services and tools to discover existing methods

Next, we need to add the middleware and then map the incoming gRPC requests to the Reflection Service.

```
builder.Services.AddGrpcReflection();

IWebHostEnvironment env = app.Environment;
if (env.IsDevelopment())
{
   app.MapGrpcReflectionService();
}

```

Once you did this, PostMan will successfully discover the available gRPC methods, and you will be able to call invoke these from the UI

![](https://irina.codes/wp-content/uploads/2022/12/image-5-1024x295.png)
_gRPC methods_

That’s it! A package and a few lines of code and you will enable gRPC server reflection.

The post [Enabling gRPC server reflection](https://irina.codes/enabling-grpc-server-reflection/) appeared first on [Irina Scurtu](https://irina.codes).