What Is gRPC and How It Works

This post discovers RPC, gRPC, JSON-RPC interfaces, and how to send JSON-RPC requests using Postman. Explore the advantages of Apidog for efficient API collaboration and management.

Build APIs Faster & Together in Apidog

What Is gRPC and How It Works

Start for free

What is RPC?

RPC stands for Remote Procedure Call, which refers to a method of invoking a function or procedure on a remote server. In simpler terms, imagine you have two servers, A and B. The application deployed on server A needs to call a method provided by another application deployed on server B. Since they are not in the same memory space, direct invocation is not possible, and network communication is required to achieve the desired call.

In everyday development, you might have encountered this concept when the front end makes requests to backend APIs. To establish a successful API request, certain rules need to be defined, such as the semantics of the call (e.g., RESTful), the network transmission protocol (e.g., HTTP), and the data serialization/deserialization format (e.g., JSON). These rules ensure standardized communication between the frontend and backend systems.

Client Server

From the diagram above, it can be seen that RPC is a client-server pattern. From a certain perspective, any calls outside of the application itself can be classified as RPC. Whether it's microservices, third-party HTTP interfaces, or interacting with database middleware like MySQL or Redis.

What is gRPC?

You can think of gRPC as an open-source framework built on top of RPC, designed with HTTP2 in mind. Therefore, gRPC inherits the advantages of HTTP2, including:

  • Binary framing for data transmission
  • Multiplexing
  • Server-side streaming
  • Header compression

How does gRPC Transmit Data?

gRPC Transmit Data

From the diagram and documentation, it can be seen that when using gRPC for remote service invocation, the client only needs a gRPC stub. The client initiates the service call to the gRPC server by sending a Proto request, and the gRPC server responds with Proto response(s) containing the result of the call.

gRPC, RPC, and JSON-RPC Interfaces

gRPC is a framework for RPC. After discussing gRPC, let's talk about how to debug an RPC interface.

RPC stands for Remote Procedure Call and is a technique used in distributed systems that allows an application to call functions or services of another application over a network. RPC can be implemented using various protocols, and JSON-RPC is one of them. It encodes and decodes data using the JSON data format and utilizes HTTP or other protocols for transmission.

How to Send a JSON-RPC Interface Using Postman

Here are the steps to call a JSON-RPC interface using Postman:

Step 1. Open Postman and create a new HTTP request.

Step 2. In the request panel, select the HTTP method as POST.

Step3. Enter the URL address of the JSON-RPC interface.

Step 4. In the Body section, select "raw - JSON" and enter the following data in JSON format:

"jsonrpc": "2.0",
"method": {{method to be called}},
"params": {{parameters required by the method}},
"id": {{unique identifier of the request}}

Step 5. Click the Send button to send the request. If everything is OK, you will see the response data in JSON format in the response panel.

Request Response

In this example, we call a method named "echo" and provide an object as the parameter. The unique identifier of the request is 123.

A Better Way: Sending JSON-RPC Interface with Apidog

You can also use Apidog to send JSON-RPC interfaces, and the transition from Postman to Apidog is almost seamless.

RPC Apidog

What is Apidog

Apidog is an integrated API collaboration platform that enables API documentation, API debugging, API mocking, and API automated testing. It is an advanced tool for API design, development, and testing. Apidog provides a comprehensive API management solution. With Apidog, you can design, debug, test, and collaborate on your APIs on a unified platform, eliminating the need to switch between different tools and ensuring data consistency. One of the features of Apidog is its support for API debugging based on API definitions. With the presence of .proto files, Apidog can provide mocking functionality and also supports automatic request body generation.