RPC: gRPC

RPC: gRPC

gRPC uses protoc with a special gRPC plugin to generate code from your proto file: you get generated gRPC client and server code, as well as the regular protocol buffer code for populating, serializing, and retrieving your message types.

The gRPC programming API in most languages comes in both synchronous and asynchronous flavors.

Alternatives are researched

In the last couple years RPC started to become popular again as a communication mechanism for web-based APIs. REST is great for modeling your domain and exposing it under a CRUD-style interface, but RPC is the way to go if your API primarily consist of executable actions (procedures).

For internal-only communication it’s better to use gRPC. Performace: gRPC is 10 times faster and consumes 30% less ressources Benchmarking gRPC+Protobuf vs HTTP+JSON

The Heir to the Throne: gRPC or Thrift

How to

I decided to go with gRPC because it’s ubiquitous.

gRPC has no direct support for building a PHP-based server. This can be done with third-party tools such as the spiral/php-grpc server

Made by google and protocol buffers

PHP can only be client, node.js can be also server and client

gRPC PHP tutorial for microservices architecture | TSH.io The Path To gRPC in Node.js. A simple guide to implementing gRPC… | by Tom Vance | Holiday Extras Tech Team

PHP Basic tutorial


Tool like cURL, but for gRPC

fullstorydev/grpcurl is cURL-like command-line tool to make requests to gRPC services.

1
2
3
4
# retrieve latest version
V=$(curl -s https://api.github.com/repos/fullstorydev/grpcurl/releases/latest | jq -r ".name")
sudo wget -q --show-progress https://github.com/fullstorydev/grpcurl/releases/download/${V}/grpcurl_${V:1}_linux_x86_64.tar.gz -O - | tar -xz -C /usr/local/bin grpcurl
# sudo chmod +x /usr/local/bin/grpcurl

Usage:

grpcurl -plaintext -proto crawler.proto -d '{ "url": "none" }' 0.0.0.0:1971 vouchers.CrawlerService/Crawl

Desktop tools

If you prefer a desktop tool, BloomRPC is the Postman of gRPC :)

date 01. Jan 0001 | modified 29. Dec 2023
filename: RPC » gRPC