Request and Response Contracts
API Contracts
A contract describes what clients may send and what the server promises to return.
A mature API contract documents required fields, optional fields, nullable fields, formats, enum values, status codes, headers, authentication requirements, and error responses.
Schema validation tools can validate requests and responses automatically. This is particularly valuable in large teams where frontend and backend evolve independently.
Key Takeaways
- Contracts define expectations between producers and consumers.
- Request validation protects the server.
- Response validation can detect accidental breaking changes.