Using Server Reflection
1. Registering Reflection Service
| Effect | Detail |
|---|---|
| Exposes | grpc.reflection.v1.ServerReflection |
| Tooling | grpcurl, Postman, Evans can call without .proto files |
2. Using grpc_cli Tool
| Command | Purpose |
|---|---|
grpc_cli ls localhost:50051 | List services |
grpc_cli ls localhost:50051 user.v1.UserService -l | List methods |
grpc_cli call localhost:50051 GetUser 'id:"u1"' | Invoke |
3. Listing Services
Example: grpcurl list
grpcurl -plaintext localhost:50051 list
grpcurl -plaintext localhost:50051 list user.v1.UserService
4. Describing Service Types
| Command | Purpose |
|---|---|
grpcurl ... describe user.v1.UserService | Service definition |
grpcurl ... describe user.v1.User | Message schema |
5. Calling Methods via CLI
Example: grpcurl invoke
grpcurl -plaintext \
-H "authorization: Bearer $TOK" \
-d '{"id":"u1"}' \
localhost:50051 user.v1.UserService/GetUser
6. Using grpcurl Tool
| Flag | Purpose |
|---|---|
-plaintext | No TLS |
-insecure | TLS without verification |
-d | JSON payload (@file.json) |
-H | Set header |
-import-path / -proto | Use without reflection |
7. Discovering Service Schema
| Use | Detail |
|---|---|
| Postman gRPC | Auto-imports via reflection |
| Codegen on the fly | Dynamic clients without .proto checked in |
8. Disabling Reflection in Production
| Reason | Mitigation |
|---|---|
| Schema leak | Disable on public services |
| Compromise | Gate behind admin port + auth |
| Build flag | Conditional register at startup |
9. Using Postman with Reflection
| Step | Detail |
|---|---|
| Create gRPC request | Set URL + check "Use reflection" |
| Pick method | Dropdown populated from reflection |
| Send | Auto-generated form for request fields |
10. Implementing Custom Reflection
| Use case | Detail |
|---|---|
| Filter methods | Hide admin-only RPCs from public reflection |
| Custom registry | Pass selective protoregistry.Files |