API Academy
🌐 English
  • 🌐 English
  • 🌐 繁體中文
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Advanced API Technologies
  • Introduction
  • Table of Contents
  • API Academy
    • Get Started
      • What is an API?
      • How Does an API Work?
      • How to Call an API?
      • How to Read an API Documentation?
      • Chapter Summary
      • Get realtime weather
    • API Fundamentals
      • API Funtamentals: Overview
      • Method & Path
      • Parameters
      • Request Body
      • Responses
      • API Specification & OAS
      • Chapter Summary
    • Working with APIs
      • Working with APIs: Overview
      • Making Requests from Spec
      • Environments and Variables
      • Chaining Multiple Endpoints
      • Handling Authentication
      • Handling API Signatures
      • Introduction to Scripts
      • Chapter Summary
    • Mocking APIs
      • Mocking APIs: Overview
      • Smart Mock
      • Mock Expectations
      • Cloud Mock
      • Mock Scripts
      • Chapter Summary
    • Designing APIs
      • Designing APIs: Overview
      • Introduction to API Design
      • Creating Your First API Project
      • Analyzing Requirements and Planning Your API
      • Designing Data Models
      • Designing Endpoints
      • Using Components and Reusability
      • Setting Up Authentication
      • API Design Guidelines
      • Chapter Summary
    • Developing APIs
      • Developing APIs: Overview
      • Setup: Install Your AI Coding Assistant
      • Quick Start: From Spec to Running API in 30 Minutes
      • Understanding the Generated Code
      • Testing Your API with Apidog
      • Deployment: Put Your API Online
      • Chapter Summary
    • Testing APIs
      • Testing APIs: Overview
      • Getting Started: Your First Test Scenario
      • Integration Testing and Data Passing
      • Dynamic Values
      • Assertions and Validations
      • Flow Control: If, For, ForEach
      • Data-Driven Testing
      • Performance Testing
      • Test Reports and Analysis
      • CI/CD Integration
      • Scheduled Tasks and Automation
      • Advanced Testing Strategies
      • Chapter Summary
    • API Documentations
      • API Documentations: Overview
      • Publishing Your First API Doc
      • Customizing Documentation Appearance
      • Interactive Features for Consumers
      • Advanced Publishing Settings
      • Managing API Versions
      • Chapter Summary
    • Advanced API Technologies
      • API Technologies: Overview
      • GraphQL
      • gRPC
      • WebSocket
      • Socket.IO
      • Server-Sent Events (SSE)
      • SOAP
      • Chapter Summary
    • API Lifecycle
      • API Lifecycle: Overview
      • Stages of the API Lifecycle
      • API Governance
      • API Security Best Practices
      • Monitoring and Analytics
      • API Versioning Strategies
      • The Future of APIs
      • Chapter Summary
    • API Security
      • API Security: Overview
      • API Security Fundamentals
      • Authentication vs Authorization
      • Understanding OAuth 2.0 and OpenID Connect
      • JSON Web Tokens (JWT)
      • OWASP API Security Top 10
      • Encryption and HTTPS
      • Chapter Summary
    • API Tools
      • API Tools: Overview
      • The Evolution of API Tools
      • API Clients
      • Command Line Tools (cURL, HTTPie)
      • API Design and Documentation Tools
      • API Mocking Tools
      • API Testing Tools
      • All-in-One API Platforms
      • Chapter Summary
    • API Gateway
      • API Gateway: Overview
      • What is an API Gateway?
      • Key Features of API Gateways
      • API Gateway vs Load Balancer vs Service Mesh
      • Popular API Gateway Solutions
      • The BFF (Backend for Frontend) Pattern
      • Chapter Summary
  • Modern Pet Store
    • Pet
      • Get Pet
      • Update Pet
      • Delete Pet
      • Create Pet
      • List Pets
      • Upload Pet Image
    • User
      • Update User
      • Get User
      • Delete User
      • Login
      • Logout
      • Create User
    • Store
      • List Inventory
      • Create Order
      • Get Order
      • Delete Order
      • Callback Example
      • Pay for an Order
    • Payments
      • Pay Order
    • Chat
      • Create Chat Completion
    • Webhooks
      • Pet Adopted Event
      • New Pet Available Event
  • Schemas
    • Pet
    • Category
    • User
    • ApiResponse
    • OrderPayment
    • Tag
    • Order
    • Links-Order
    • PetCollection
    • Bank Card
    • Bank Account
    • Links
    • Error
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Advanced API Technologies

gRPC

What is gRPC?#

gRPC (Google Remote Procedure Call) is an open-source high-performance RPC framework that runs over HTTP/2. It was released by Google in 2015.
REST APIs typically use JSON (a text-based format) over HTTP/1.1. In contrast, gRPC uses Protocol Buffers (Protobuf), a binary format, to serialize data. This results in smaller payloads and faster processing, making gRPC ideal for low-latency communication between microservices.

Core Concepts#

1.
Protocol Buffers (Protobuf): The Interface Definition Language (IDL) used to define the service API and payload messages.
2.
HTTP/2 Transport: Enables multiplexing (multiple requests over one connection), header compression, and server push.
3.
Strict Contract: The .proto file acts as the single source of truth. Both client and server code are generated from this definition.
4.
Streaming: Native support for streaming data in both directions.

Code Example: The .proto Contract#

Everything starts with a definition file:

The 4 Communication Modes#

1.
Unary RPC: The client sends a single request and gets a single response. (Similar to a standard function call or REST request).
2.
Server Streaming: The client sends a request and receives a stream of messages. The client reads until there are no more messages.
3.
Client Streaming: The client writes a sequence of messages to the server. Once finished, the server sends a single response.
4.
Bidirectional Streaming: Both sides send a sequence of messages using a read-write stream. The two streams operate independently.

Comparisons: gRPC vs. REST#

FeatureRESTgRPC
ProtocolHTTP/1.1 (usually)HTTP/2
PayloadJSON / XML (Text)Protobuf (Binary)
ContractOptional (OpenAPI)Required (.proto)
StreamingLimited (Chunked transfer)Native (Bi-directional)
Browser SupportUniversalLimited (requires gRPC-Web proxy)
Use CasePublic APIs, Web ClientsInternal Microservices, Mobile Apps

Working with gRPC in Apidog#

Apidog simplifies the complexity of testing binary gRPC endpoints by providing a user-friendly interface.

1. Create a gRPC Project#

Select New Project -> gRPC Project. Apidog handles gRPC separately to optimize for its specific lifecycle.

2. Import Definition (.proto)#

You don't manually type endpoints in gRPC.
1.
Click the + button.
2.
Import .proto: Upload your local file.
3.
Server Reflection: If your server supports reflection, enter the URL, and Apidog will auto-discover available services.
apidog-grpc-03.gif

3. Invoking Methods#

Apidog translates your JSON input into Protobuf binary automatically.
Select the method from the sidebar.
Enter parameters in the JSON body editor.
Click Invoke.
For streaming methods, the Timeline View is essential. It shows the exact sequence of messages sent and received, allowing you to debug race conditions or timing issues in real-time.
See details gRPC

Key Takeaways#

High Performance: gRPC uses Protocol Buffers (binary) and HTTP/2 for low-latency, high-throughput communication.
Strict Contracts: The .proto file is the source of truth, allowing code generation for both client and server.
Streaming: Native support for Server, Client, and Bidirectional streaming makes it ideal for real-time data feeds.
Apidog Support: Apidog handles the binary encoding complexities for you, allowing you to test gRPC with simple JSON inputs.
Continue with β†’ WebSocket
Modified atΒ 2025-12-25 10:12:25
Previous
GraphQL
Next
WebSocket
Built with