0Pricing
gRPC & High Performance APIs · Lekcja

Refleksja serwera i klienci dynamiczni

Włącz refleksję serwera gRPC, aby narzędzia i klienci mogli w czasie działania wykrywać usługi i schematy komunikatów bez wstępnie skompilowanych stubów.

Refleksja serwera i klienci dynamiczni to bezpłatna lekcja gRPC & High Performance APIs na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej gRPC & High Performance APIs, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs gRPC & High Performance APIs zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

The Stub Discovery Problem

Normally a client needs the .proto files compiled into stubs to call a service. That is inconvenient for debugging tools and generic clients.

Server reflection lets a server describe its own API at runtime.

What Reflection Exposes

The reflection service answers questions like:

  • Which services does this server host?
  • What methods does a service have?
  • What are the request/response message schemas?

It returns the underlying FileDescriptorProto data.

Enabling Reflection in Go

Register the reflection service on your gRPC server with a single call.

import 'google.golang.org/grpc/reflection'

s := grpc.NewServer()
pb.RegisterServiceServer(s, &svc{})
reflection.Register(s)

Enabling Reflection in Java

In Java add the ProtoReflectionService when building the server.

Server server = ServerBuilder.forPort(9090)
  .addService(new MyServiceImpl())
  .addService(ProtoReflectionService.newInstance())
  .build();

Listing Services with grpcurl

With reflection on, grpcurl can list services without a proto file.

grpcurl -plaintext localhost:9090 list

Describing a Method

You can inspect a method's input and output schema directly from the server.

grpcurl -plaintext localhost:9090 describe my.pkg.Service.GetUser

Calling Without Stubs

Reflection lets you invoke methods by sending JSON; the tool maps it to protobuf using the discovered schema.

grpcurl -plaintext -d '{"id": 7}' localhost:9090 my.pkg.Service.GetUser

Dynamic Clients in Code

Libraries can build messages dynamically from descriptors fetched via reflection, enabling generic gateways and admin tools that work against any gRPC server.

The Reflection Protocol

Reflection is itself a gRPC service: grpc.reflection.v1.ServerReflection. It uses a bidirectional stream where clients ask and the server streams back descriptors.

Security Considerations

Reflection reveals your entire API surface. In production:

  • Disable it on public-facing edges, or
  • Restrict it to internal networks / authenticated callers

It is invaluable in dev and staging.

When to Use It

Reflection shines for debugging, building generic UIs (like BloomRPC/Postman), and admin tooling. For high-throughput app clients, precompiled stubs are still faster and safer.

Quick Check

Test your reflection knowledge.

Recap

You learned server reflection and dynamic clients:

  • Reflection lets a server describe its own API at runtime
  • Enable it with reflection.Register (Go) or ProtoReflectionService (Java)
  • Tools like grpcurl can list, describe, and call without stubs
  • Dynamic clients build messages from fetched descriptors
  • Restrict reflection in production for security

Często zadawane pytania

Czy lekcja „Refleksja serwera i klienci dynamiczni” jest bezpłatna?

Tak — pełny tekst „Refleksja serwera i klienci dynamiczni” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu gRPC & High Performance APIs, przejdź na CoddyKit PRO. Kurs gRPC & High Performance APIs zawiera 4 lekcji w sumie.

Co nauczysz się w „Refleksja serwera i klienci dynamiczni”?

Włącz refleksję serwera gRPC, aby narzędzia i klienci mogli w czasie działania wykrywać usługi i schematy komunikatów bez wstępnie skompilowanych stubów. Ćwiczysz gRPC & High Performance APIs z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć gRPC & High Performance APIs?

Nie wymagamy żadnego doświadczenia. gRPC & High Performance APIs w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Refleksja serwera i klienci dynamiczni”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji gRPC & High Performance APIs?

Tak. Każda lekcja gRPC & High Performance APIs zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Integracja gRPC-Web
  2. gRPCurl i BloomRPC
  3. Wzorce wykrywania usług
  4. Refleksja serwera i klienci dynamiczni
← Powrót do gRPC & High Performance APIs