Advertisement
Intermediate ASP.NET Core, gRPC Services

How do you enable and use gRPC reflection for service discovery and debugging tools like grpcurl or Postman?

Short answer

The Grpc.AspNetCore.Server.Reflection package, registered via AddGrpcReflection() and app.MapGrpcReflectionService(), exposes metadata about a gRPC service's available methods and message types at runtime without needing the original .proto file -- essential for generic…

Save ASP.NET Core mock interview
Advertisement
AModel answer
The Grpc.AspNetCore.Server.Reflection package, registered via AddGrpcReflection() and app.MapGrpcReflectionService(), exposes metadata about a gRPC service's available methods and message types at runtime without needing the original .proto file -- essential for generic debugging/testing tools like grpcurl, Postman, or BloomRPC to introspect and call a gRPC service interactively during development, though it's typically disabled in production for security reasons.
// Program.cs
#if DEBUG
builder.Services.AddGrpcReflection();
#endif

var app = builder.Build();
#if DEBUG
app.MapGrpcReflectionService();
#endif

# Using grpcurl with reflection enabled
grpcurl -plaintext localhost:5001 list
grpcurl -plaintext -d '{"name": "World"}' localhost:5001 Greeter/SayHello
Real-world example
A development team enables gRPC reflection only in Debug builds, letting engineers use grpcurl to interactively explore and test a gRPC service's available methods during local development without needing to share or track down the exact .proto file.
Likely follow-ups
  • Why is reflection typically disabled in production, and what's the security concern?
  • What's the equivalent of Swagger UI for browsing gRPC service documentation?
Related topics