REST at Layer 5: Designing the API Layer
The API layer has one job: protocol translation. What a thin REST route looks like, how domain errors become status codes, and how to pick a versioning style.
The REST API shipped, and then the requests arrived. The mobile team wants one round trip per screen, so they ask for GraphQL. The data team wants typed streaming between services, so they ask for gRPC. A partner wants documentation that is actually correct. Each request is a new surface, and each new surface is a fresh chance for business rules to be copied into it.
LVD's answer is that every protocol is an adapter over the same tools. The business logic is written once in Layer 4, and each protocol exposes it in its own dialect.
GraphQL offers one endpoint with a strongly typed schema. In an LVD system that schema mirrors the Layer 1 definitions, and resolvers delegate straight to tool handlers. A resolver should read like a route: authenticate, call a handler, return its data.
export const resolvers = {
Query: {
ride: async (_parent, { rideId }, ctx) => {
assertAuthenticated(ctx);
const result = await getRideHandler({ rideId, riderId: ctx.user.id });
return result.data;
},
},
};
gRPC uses Protocol Buffers as its interface language, and in LVD the .proto files serve as another representation of the schema layer. gRPC supports four call styles: one request and one response, a stream of responses, a stream of requests, and streams in both directions. It shines for service-to-service traffic, where strong typing, performance and streaming matter most. REST remains the better fit for browser-facing and public APIs, where readability counts. Nothing stops a system from offering both side by side as separate adapters.
GraphQL brings a well-known trap. Ask for a list of rides and, for each ride, its driver, and a naive resolver makes one database call per ride. This is the N+1 problem. The standard remedy is a DataLoader, which collects the lookups made during one request and turns them into a single batched call.
The book is specific about where this fix lives: in the API layer. Batching is a trick of the GraphQL protocol, so it belongs with the protocol adapter, and the tool handler underneath stays unaware of it. It only needs to offer a batch-capable operation for the loader to call.
Real-time subscriptions follow the same principle of direction. The subscribing side lives in the API layer, but the event that feeds it comes from a tool through an event emitter that is injected via the Resources layer. Dependencies keep pointing downward even when the data flows upward to a waiting client.
Hand-written API documentation is a promise that decays. The book's alternative is to generate it from the schema layer. Because the Layer 1 schemas already describe every request and response, a library such as zod-to-openapi can produce an OpenAPI specification directly from them, and the output refreshes at build time whenever a schema changes. There is no second source of truth to forget about.
The generated specification earns its keep twice. The UI layer builds its typed API client from it, so the client is generated during the build and never edited by hand. Continuous integration regenerates the client and fails when the output differs from the committed copy, which means a schema change that was not propagated cannot merge.
Think about what that does to a team's habits. Updating the docs stops being a task someone must remember and becomes a side effect of changing the contract. It also turns the API's description into something a machine checks on every build, which is a far stronger guarantee than a reviewer's attention.
REST, GraphQL and gRPC are three presentations of one set of tools, and the generated documentation is a fourth view of the same schemas. The discipline is the same each time: translate at the edge, keep business logic out, and put protocol-specific tricks in the protocol layer. The groundwork is in REST at Layer 5, and the generated client is what the UI relies on in the UI's API boundary. For the layer overview, see the Layer 5 page.