Get Book (gRPC) (v1.0.0)

Get a book by ID via gRPC

Overview

This gRPC endpoint follows Domain-Driven Design principles to retrieve a specific Book aggregate root from the Catalog bounded context by its unique identifier. The operation is implemented as a query that doesn’t modify state, adhering to CQRS patterns.

The query handler maps the domain entity to a BookDto response through an auto-mapper profile, ensuring that domain implementation details remain encapsulated. The endpoint respects the aggregate boundaries and only exposes data appropriate for the presentation layer.

Key Features

  • High Performance: gRPC binary protocol for efficient data transfer
  • Strong Typing: Protocol buffer definitions ensure type safety
  • Streaming Support: Capable of server streaming for bulk operations
  • Cross-Platform: Works with any gRPC-compatible client

Architecture

Usage

Call GetBook using grpcurl

You can use grpcurl to call the GetBook method of the BookGrpcService defined in your book.proto:

Terminal window
grpcurl -plaintext \
-d '{"bookId": "<BOOK_ID>"}' \
localhost:5001 \
CatalogApi.BookGrpcService/GetBook
  • Replace <BOOK_ID> with the actual book ID (string).
  • Adjust the host/port (localhost:5001) as needed for your environment.
  • The response will be a BookResponse message as defined in your proto:
200 OK
{
"id": "<BOOK_ID>",
"name": "Atomic Habits",
"price": { "units": 12, "nanos": 0 },
"priceSale": { "units": 10, "nanos": 0 },
"status": "InStock"
}
id string <uuid>

The unique identifier for the book

name string

The name of the book

price number <double>

The price of the book

priceSale number <double>

The sale price of the book

status string

The status of the book