gRPC Client

Native gRPC client component for Delphi/C++Builder. Unary and streaming calls over HTTP/2, custom metadata, deadlines, gzip compression, interceptors, automatic retry and TLS via OpenSSL or Windows SChannel. Bring any Protocol Buffers encoder; the component frames and ships your message bytes.

TsgcGRPCClient

A typed gRPC client that runs on top of the native TsgcHTTP2Client transport. Unary and all three streaming modes, status and trailer parsing, no external gRPC runtime or C library.

Component class

TsgcGRPCClient

Protocol

gRPC over HTTP/2 (RFC 9113)

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Enterprise

Wire the transport, make a call

Drop a TsgcHTTP2Client and a TsgcGRPCClient on a form, assign the transport, then call your service method with the request bytes.

uses
  sgcHTTP2, sgcGRPC_Client, sgcGRPC_Classes, sgcGRPC_Types;

var
  HTTP2: TsgcHTTP2Client;
  GRPC: TsgcGRPCClient;
  oResponse: TsgcGRPCResponse;
begin
  // gRPC runs over an HTTP/2 transport
  HTTP2 := TsgcHTTP2Client.Create(nil);
  HTTP2.Host := 'grpc.example.com';
  HTTP2.Port := 443;
  HTTP2.TLS  := True;

  GRPC := TsgcGRPCClient.Create(nil);
  GRPC.Client := HTTP2;

  // default metadata sent on every call (auth, tracing...)
  GRPC.DefaultMetadata.Add('authorization', 'Bearer eyJ...');

  // unary call: pass your serialized protobuf message as TBytes
  oResponse := GRPC.Call('helloworld.Greeter', 'SayHello', RequestBytes);
  if oResponse.StatusCode = grpcOK then
    Memo1.Text := oResponse.DataString
  else
    ShowMessage('gRPC error: ' + oResponse.StatusMessage);
end;
// uses: sgcHTTP2, sgcGRPC_Client, sgcGRPC_Classes, sgcGRPC_Types
TsgcHTTP2Client *HTTP2 = new TsgcHTTP2Client(NULL);
HTTP2->Host = "grpc.example.com";
HTTP2->Port = 443;
HTTP2->TLS  = true;

TsgcGRPCClient *GRPC = new TsgcGRPCClient(NULL);
GRPC->Client = HTTP2;

GRPC->DefaultMetadata->Add("authorization", "Bearer eyJ...");

TsgcGRPCResponse *oResponse = GRPC->Call("helloworld.Greeter", "SayHello", RequestBytes);
if (oResponse->StatusCode == grpcOK)
  Memo1->Text = oResponse->DataString;

What's inside

A complete gRPC client built on the sgcHTTP2 framing engine. Four call types, channel tuning, metadata, deadlines, interceptors and retry.

Unary calls

Call blocks and returns a TsgcGRPCResponse with StatusCode, StatusMessage, Data and Trailers. CallAsync returns immediately and fires OnGRPCResponse.

Server streaming

ServerStreamingCall sends one request and receives a stream of messages. Each message raises OnGRPCStreamMessage; OnGRPCStreamEnd fires with the final status.

Client streaming

OpenClientStream opens the stream, SendStreamMessage pushes each message, and CloseClientStream half-closes and reads the single server reply.

Bidirectional streaming

OpenBidiStream, SendBidiMessage and CloseBidiStream run a full-duplex exchange over a single HTTP/2 stream, both sides sending at once.

Metadata, deadlines, cancel

DefaultMetadata and per-call metadata carry auth and tracing headers. A per-call timeout maps to the grpc-timeout header, and CancelCall aborts an in-flight stream.

Channel options

ChannelOptions tunes gzip Compression, ContentType, MaxMessageSize and MaxMetadataSize for the whole channel.

Interceptors, retry, service config

An Interceptors chain wraps every call, RetryPolicy retries on configurable status codes, and ServiceConfig plus MetricsCollector add per-method policy and counters.

Built on HTTP/2 and TLS

The transport is TsgcHTTP2Client: ALPN h2, TLS via OpenSSL or SChannel, and parsing of grpc-status / grpc-message trailers into typed status codes.

Protobuf-agnostic, with Google clients

Calls take and return raw message bytes, so any Protocol Buffers library works. Typed Google Cloud clients (Pub/Sub, Speech, Translation, Vision, BigQuery, Vertex AI) ship on top.

Specifications & references

Authoritative sources for the protocol this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — TsgcGRPCClient Full property, method and event reference for this component.
Demo Project — Demos\21.GRPC\01.GRPC_Client Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to call gRPC services from Delphi?

Download the free trial and add unary and streaming gRPC to your Delphi applications.