gRPC: what it is and how it differs from REST
gRPC is a remote procedure call framework: a client calls a service method almost like a local function, and the contract lives in a .proto file. The transport is HTTP/2 and the default message format is Protocol Buffers: binary, compact and strictly schematised. The result is decided not by the HTTP status but by grpc-status in the trailers, so QA needs the schema, a generated client and a check of that status.
API · gRPC
A team moves from REST to gRPC. What changes for tests and for the contract?
The morning after a migration: curl against the new service returns an unreadable binary stream or a protocol error, and Postman asks for a .proto upload instead of a URL with a GET. Tests written as "an HTTP request and JSON in the response" do not work here. The lesson explains what gRPC is, how its model differs from REST and what follows from that for QA.
How it works and why it is designed so
gRPC is a remote procedure call (RPC) framework: a client calls a service method almost like a local function. There is one contract, described in a .proto file; the client and the server stubs for many languages are generated from it. The transport is HTTP/2, the default message format is Protocol Buffers: binary, compact, with a strict schema. The "schema before code" decision removes a whole class of errors: the two sides cannot disagree on a field name or type because both are generated from one file.
syntax = "proto3";
package shop.v1;
service OrderService {
rpc GetOrder (GetOrderRequest) returns (Order);
rpc WatchOrders (WatchRequest) returns (stream Order);
}
message GetOrderRequest { string id = 1; }
message Order {
string id = 1;
int64 total_cents = 2;
Status status = 3;
}
enum Status { STATUS_UNSPECIFIED = 0; PAID = 1; SHIPPED = 2; }
From schema to a call
The binary format and HTTP/2 multiplexing (many streams in one connection) give smaller messages and lower latency than JSON over HTTP/1.1. The price: a message cannot be read by eye, and any interaction needs the schema.
Worked example: the same call in two models
In REST an order is read like this:
GET /orders/42 HTTP/1.1
Authorization: Bearer <token>
HTTP/1.1 404 Not Found
gRPC has no equivalent request line: the method OrderService/GetOrder is invoked with a POST to the path /shop.v1.OrderService/GetOrder, and the result is decided not by the HTTP status but by grpc-status in the trailers (details in the lesson on statuses). In practice that means three changes in the work:
- Manual checks go through grpcurl, Postman or Insomnia, and they need the schema: from a
.protofile or through server reflection. - Automated tests are written on a generated client: a mismatch with the schema is caught by the compiler, not by a late run.
- The contract is now a file that can be checked automatically: a linter and a backward-compatibility check in CI.
Limits and alternatives
REST and gRPC: what differs
Resources and verbs
JSON you can see in a browser or curl. The schema (OpenAPI) is optional and can drift from the implementation. Works in a browser directly.
Method calls
Binary Protobuf over HTTP/2. The .proto schema is mandatory and typed. Streaming out of the box. A browser needs grpc-web or Connect.
- Browser. Browser JavaScript cannot control HTTP/2 frames and trailers, so direct gRPC is unavailable. Solutions: grpc-web through a proxy (for example Envoy), the Connect protocol or gRPC-Gateway with REST/JSON on top of the service.
- GraphQL gives the client an arbitrary query shape against one endpoint; gRPC fixes the set of methods and shapes in advance.
- Where it is used. Internal microservice calls, low latency, streaming, mobile clients, teams with different languages. Public APIs for third-party developers more often stay REST.
Common mistakes
- Expecting an HTTP code as the result: almost always a 200 arrives and the error sits in
grpc-status. - Writing tests on hand-written JSON wrappers instead of the generated client: mismatches with the schema come back.
- Not testing the gateway (grpc-web, gRPC-Gateway): it has its own mapping of statuses to HTTP and its own JSON serialisation.
Check yourself
A team says: "we described everything in OpenAPI, so we do not need a .proto". Is that possible for gRPC?
Answer
No. The gRPC client and server are generated from .proto, and it determines how messages are encoded into bytes. OpenAPI describes HTTP/JSON and is not related to a gRPC service, except for a gateway that exposes REST on top of it.
Why does a test that checks only the HTTP status of a gRPC call prove almost nothing?
Answer
The server answers HTTP 200 whatever the result, and the real status arrives in the trailers as grpc-status. Such a test stays green on NOT_FOUND and on INTERNAL alike.
grpc-status instead of an HTTP code, a linter and a schema compatibility check in CI, and separate gateway tests if there is one.