Skip to main content
  1. Posts/

Stop Writing API Boilerplate: Let Orval Generate It For You

· loading · loading ·
Jared Lynskey
Author
Jared Lynskey
Emerging leader and software engineer based in Seoul, South Korea
OpenApi - This article is part of a series.
Part 2: This Article

In the first post of this series I made the case for agreeing on an OpenAPI contract before anyone writes code. This one is about the tool that makes the contract actually pay off: Orval.

Hand-writing the frontend’s API layer is one of those jobs nobody admits to enjoying. You copy types out of the backend docs, write the same request wrapper for the fortieth time, and three weeks later someone renames a field and half your calls quietly break. Orval deletes that job. Point it at your OpenAPI spec and it generates the client code for you: typed functions for every endpoint, models that match the contract exactly, and mocks you can develop against before the backend exists.

Why the frontend team likes it
#

The mock generation is the underrated part. Once the spec is agreed, the frontend can spin up a fake server and build the entire UI against it, instead of waiting for endpoints that are perpetually “almost done”. When the real backend lands, you point the client at it and things mostly just work, because both sides were built from the same document.

The other win is that the boring code is now correct by construction. Nobody fat-fingers a field name in a hand-rolled request body, because nobody writes a hand-rolled request body anymore.

Why the backend team likes it too
#

The spec being the single source of truth changes the day-to-day conversations. Instead of chat threads asking “what does this endpoint return again?”, the frontend just reads the generated types. Backend devs get interrupted less, and they get feedback sooner: if the frontend builds against the mocks and something about the API feels awkward, you find out while it’s still cheap to change, not after it’s in production.

How it fits the workflow
#

Nothing fancy. The backend proposes the spec, both teams review it, the frontend generates the client and mocks with Orval and starts building, and the backend implements the real endpoints to the same contract. When the spec changes, both sides regenerate, and the compiler tells you exactly what broke. That last part is the whole point: drift between frontend and backend becomes a compile error instead of a production bug.

It’s not glamorous tooling. It just quietly removes a whole category of arguments between teams, and I’ll take that trade every time.

OpenApi - This article is part of a series.
Part 2: This Article