The API schema before the code: how we speed up frontend and backend
Designing an API without a schema is an invitation to chaos. We start contract-first: we describe OpenAPI/JSON Schema before the first line of code. This lets the frontend and the backend work in parallel and rules out surprises at integration time.
What the process looks like
- We create the domain model and ER diagrams together with a business analyst.
- We fix the interfaces in OpenAPI 3.1 and generate a mock server and a Postman collection.
- We plug in type generators for React, iOS, Android and server-side services.
While the API is being implemented, the frontend tests the contract against the mock, QA writes automated tests on ready-made examples, and analysts verify the scenarios. After release, contract tests do not let anyone accidentally break the public API. And if the service is written with FastAPI, some of these checks are convenient to build on dependency injection; we showed how this works in the article on testing FastAPI through Dependency Injection.
Toolset
- Stoplight / SwaggerHub: visual schema editing and discussions with the business.
- Prism: a mock server that can validate requests against the schema.
- openapi-generator: types for TypeScript, Kotlin and Swift from a single source.
- Dredd / Schemathesis: contract tests that run in CI.
A single catalog of schemas gets rid of "verbal agreements" and cuts the time needed to onboard new engineers.
Change control
The schema is stored in the repository next to the code, but changes go through a separate pull request. We use linters (Redocly) and an automatic versioning check: if a field is removed or changes type, the pipeline requires a major version bump. For external clients we publish a changelog with request/response examples and migration tips.
Before a release we run compatibility tests: old clients are run against the new schema, and new clients against the previous version of the API. This eliminates "broken" releases before they reach staging.
AnvilCode case
In an e-commerce project we moved 40 REST endpoints to contract-first. Previously the frontend waited for the backend for 2-3 sprints; now the teams work in parallel. The mock server let the marketing department test the customer account area before the production API existed.
The result:
- Feature delivery time dropped from 12 to 7 weeks.
- The number of integration bugs fell by 45%: errors are caught at the contract test stage.
- We got a single set of documentation that both the developer and the product owner can understand.
Contract-first is not bureaucracy but an investment in transparency. When the schema is the source of truth, teams spend their time on the product, not on negotiating formats.
How we focus on API UX
A schema is also an interface for the developer. We run design reviews of an API as carefully as UX reviews of a user interface: we assess the readability of endpoints, consistency of naming, predictability of statuses. An important principle is idempotent methods wherever the team expects repeated requests (for example, on an unreliable connection).
During a review we ask three questions: "Will an integrator understand the purpose of a resource within a minute?", "What happens if the client sends an incomplete payload?", "What do the happy path and the error case look like in the documentation?". We keep these checklists in the repository and update them together with the schema, so a new developer instantly understands the standards.
Security and compliance
Once the schema is formalized, it is easier to introduce security and compliance requirements. We integrate security scanners (42Crunch, StackHawk) that analyze OpenAPI and look for vulnerabilities: missing rate limiting, unencrypted fields, weak authorization schemes. The results go into CI, and a pull request does not pass until the risks found are resolved.
For personal data audits we add the x-pii and x-sensitive extensions to the schema. This
makes it possible to automatically build a registry of fields that contain PII and to control where they are
logged. When we onboard a new country with local regulation, we check compliance
right in the schema, not in the code.
Managing versions at scale
In large systems dozens of teams revise the API at the same time. To avoid drowning in merge conflicts, we run the schema through a contract-first process: every change lives in its own schema branch. Until the implementation is ready, the branch is marked "draft" and synchronized with consumers through a preview environment. As soon as the service is ready, the merge happens together with a version bump and an automatic update of the SDKs.
In parallel we maintain a compatibility matrix: which client versions each API supports. This lets teams plan the retirement of legacy versions and notify external partners in advance. Saying goodbye to an outdated schema happens without night-time migrations and integrations "going down".
Tips for getting started
- Start with a pilot on one domain: pick a flow with many integrations or complaints.
- Define a "schema keeper", a role responsible for consistency and review.
- Prepare templates for release notes and breaking changes in advance: it saves hours during a release.
- Teach the team to read OpenAPI: short workshops work better than long regulations.
The contract approach is discipline and respect for API consumers. It lets you build complex platforms without chaos, scale teams and launch new products without breaking the old ones.