Загрузка…
Загрузка…
gRPC — method-centric RPC: .proto → typed codegen, binary Protobuf over HTTP/2. REST/GraphQL — data-centric; gRPC выглядит как локальный method call через сеть.
REST и GraphQL — resources/graph. gRPC — method-centric: userService.GetUser({ id: 7 }) — method call, но network round trip. Контракт — .proto, compile обе стороны → no drift.
// user.proto — the single source of truth for BOTH client and server
service UserService {
rpc GetUser(GetUserRequest) returns (User); // unary
rpc ListUsers(ListReq) returns (stream User); // server streaming
rpc Chat(stream Msg) returns (stream Msg); // bidirectional streaming
}
message User { int32 id = 1; string name = 2; } // field NUMBERS are the contractProtobuf — compact binary, tag numbers без имён на wire. HTTP/2 — multiplexing + native streaming. Built for service-to-service microservices backend.
Browser — gRPC-Web через proxy; теряет full bidi streaming.
gRPC = typed contracts + small fast payloads для backend; browser path — gRPC-Web с ограничениями.
