liveBook · Manning

gRPC

As explained in Learn Go with Pocket-Sized Projects

gRPC is a remote procedure call framework for communicating between distributed services.

gRPC connects distributed services through remote procedure calls, carrying lightweight Protocol Buffers messages over HTTP/2. Define messages and service endpoints in .proto files, then generate language-specific clients and server interfaces. section 10.0 section 10.1

A practical gRPC service typically combines:

  • A language-neutral API defining request messages, response messages, and callable endpoints. section 10.1
  • Generated Go interfaces and structures that connect the API definition to implementation code. section 10.1
  • An API layer that converts transport-specific values into domain objects and maps domain results back into responses. section 10.3.2
  • Status-code-based error handling, returning InvalidArgument for bad input and Internal for unexpected failures. section 10.3.2
  • Context propagation, integration tests, dependency injection, and small interfaces to keep service behavior testable. section 10.0 section 10.8

Habits service

A habits tracker exposes CreateHabit, ListHabits, TickHabit, and GetHabitStatus. A client can call CreateHabit with grpcurl using a JSON request, while the server validates the input, invokes domain logic, and returns a generated response or standardized status error. section 10.0 section 10.3.2 section 10.3.2

Listing 10.1 Habits service API
// Habits is a service for registering and tracking habits.
type HabitsService interface {
    // CreateHabit is the endpoint that registers a habit.
    CreateHabit(CreateHabitRequest) (CreateHabitResponse, error)

    // ListHabits is the endpoint that returns all habits.
    ListHabits(ListHabitsRequest) (ListHabitsResponse, error)

    // TickHabit is the endpoint to tick a habit.
    TickHabit(TickHabitRequest) (TickHabitResponse, error)

    // GetHabitStatus is the endpoint to retrieve 
    // the status of ticks of a habit.
    GetHabitStatus(GetHabitStatusRequest) (GetHabitStatusResponse, error);
}

Inspect the service contract showing request and response types for the four habits endpoints. section 10.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains API definitions, code generation, contexts, endpoint layering, status errors, manual testing, and integration testing.
Examples
Uses a habits tracker with create, list, tick, and status endpoints, plus grpcurl commands for manual requests.
What it assumes
Assumes Go programming and API familiarity while teaching Protobuf definitions, generated code, contexts, and gRPC status handling.
What you can do after
Builds and tests a Go gRPC service with generated APIs, domain validation, mapped errors, and grpcurl-based manual calls.
How it connects
Connects Protocol Buffers, HTTP/2, API design, Go contexts, status codes, integration testing, and dependency injection.

Also explained in

Compare how 10 books explain gRPC →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.