Where the UI Meets the API: Shaping Data and Translating Errors

Open the network panel on the trip summary screen of a ride-sharing app and watch four requests fire: the trip, the driver, the vehicle, the receipt. The screen joins them, retries the flaky one, and shows a different apology depending on which call failed. Nobody decided that the UI would become an integration layer. It simply happened, one screen at a time.

Where glue code lands by default

When an API is shaped around general-purpose resources, the screen that needs a bit of each has to do the assembling. That work is cheap to start and expensive to keep. The same stitching is repeated by every client, the loading states multiply, and a partial failure leaves the page half drawn.

The book's remedy is an endpoint in the API layer built for one screen, the pattern usually called a backend for frontend. It composes existing Tools and returns precisely what the screen displays, which keeps the joining work on the server and leaves the screen with little to do. For the trip summary, that means one call and one failure to handle.

One caution I would add

A screen-shaped endpoint is easy to misuse. Its job is composition: gather, rename, trim. The moment it starts deciding things, such as whether the rider qualifies for a refund, you have created a second home for business rules, with the usual consequences. Decisions still belong in a Tool, and the endpoint only calls it. A good smell test is whether the endpoint's code would make sense to someone who has never seen the business rules.

Failures need a translator

The second job at the seam concerns what goes wrong. The network speaks in numbers and users do not. Left alone, every component ends up with its own idea of what a failure means:

// BookingForm.tsx
if (res.status === 409) toast("That slot was just taken");
// WaitlistButton.tsx
if (res.status === 409 || res.status === 412) openConflictModal();
// RescheduleLink.tsx
if (!res.ok) toast("Something went wrong");

Three components, three behaviours, one underlying event. Add a rate-limit response next year and each file has to be found and edited.

The book puts the translation in a single place inside the UI's service code, and components are handed a handful of UI-level outcomes instead of raw numbers. I like that choice, and a few design notes from general practice make it work better:

  • Name kinds after the reaction, not the cause. A kind such as "ask the user to sign in again" or "offer a retry later" tells a component what to do. "HTTP 429" tells it nothing.
  • Keep a catch-all. Any status the mapping does not recognise falls into a generic failure kind with a safe message, so a new server response never crashes a screen.
  • Let only this module know HTTP. If the transport changes, or a status gets reused for a new purpose, one file changes and the components stay as they were.

Why the seam is worth fencing

Both jobs rest on the same observation: the boundary is the narrowest point of contact between the layer that changes most and the layer beneath it. Narrow contact means that most redesigns never touch the API, and most API changes surface in one place. The book strengthens the arrangement by having the typed client the UI calls through be generated from the API specification, so that a contract change is reported by the compiler rather than discovered in production.

The same seam is where Axiom A6 does its work from the other side. The UI may know the published contract, and it may not know how the layers behind it are built. Everything above is the practical consequence of that rule: the screen asks for what it needs, and the API layer worries about where it comes from.

The takeaway

Put assembly on the server side of the seam and interpretation on the UI side, each in exactly one place. Screens then stay small, errors read the same everywhere, and nothing deeper needs to know what a button looks like. For the API layer's side of this arrangement, see REST at Layer 5, and for how the UI handles the data it receives, thin components and honest state.

What the book covers

  • How the typed client is generated from the Schema layer through the API specification
  • The book's own status-to-error-kind mapping and where it lives
  • Where authentication tokens may and may not be kept in a browser
  • What the UI's part in sign-in is, and what stays in the API layer
  • What Layers 5 to 8 must publish so the UI has a contract to consume