Search⌘ K
AI Features

Types of gRPC APIs

Explore the four main types of gRPC APIs—Unary, Server Streaming, Client Streaming, and Bidirectional Streaming—and understand how each facilitates different patterns of data exchange between clients and servers. Learn how the StreamObserver interface manages streams and how these communication styles differ from REST.

gRPC communication styles

gRPC provides various streaming options for handling communication between clients and servers. Four types of streaming are available:

  1. Unary: request-response model

  2. Server streaming: The server sends a stream of messages to the client.

  3. Client streaming: The client sends a stream of messages to the server.

  4. Bidirectional streaming: The client and server send a stream of messages to each other.

Depending on the nature of the application and the requirements of data exchange, developers can choose between them to create efficient and interactive systems. In Java gRPC implementations, a special interface called StreamObserver is commonly used to handle data flows.

RPC and REST communication differ in terms of the service methods. In RPC, service methods are invoked directly using method calls. The clients know all the service methods. On the other hand in REST, service methods are represented by resource endpoints identified by URLs, and clients interact with these endpoints by sending HTTP requests. The actual methods executed are hidden from the client. ...