What it is
An API contract specifies what a client sends and what the server returns, including errors and compatibility rules. The browser displays the result, while the server validates input, identity, permissions, and business constraints.
Why you need it
Two components can compile successfully and still disagree about a field name, a null value, or what a success response means. The contract makes those assumptions explicit.
How it works
- The form collects input and gives immediate feedback.
- The client sends a documented request shape.
- The server validates and persists the allowed operation.
- The response lets the UI distinguish saved, rejected, and uncertain outcomes.
A small profile-update contract
PATCH /profile
Content-Type: application/json
{"displayName":"Amina","version":7}
200: {"displayName":"Amina","version":8}
422: {"errors":{"displayName":"Enter a shorter name"}}
409: {"code":"VERSION_CONFLICT"}These are example application semantics. Define them with both client and server implementers. A timeout is not one of these known responses: the write may have happened even if its reply was lost.
Good practices and why
- Validate on both sides for their different purposes: usability in the client and correctness at the server.
- Evolve responses compatibly while older clients may still be running.
Common mistakes
- Trusting client validation as the authoritative rule.
- Showing saved before deciding how a failed or conflicting request will be reconciled.
Try it yourself
Write request and response examples for a task-creation form, including invalid title, expired login, and network uncertainty.
What a successful result looks like
The UI has a deliberate behavior for every response and does not create duplicates blindly after a timeout.
0 / 6000 characters · Saved on this device. Do not include passwords or private data.
Check your understanding
Answer the understanding check correctly to record exercise completion.
Related interview practice
These scenarios add constraints and follow-up questions to the concepts you just learned.
Further reading
Selected primary references · reviewed 2026-10-09. Examples are educational; use your framework’s documented integration guidance when building a deployed system.