Code-first vs contract-first
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
compare the two ways of producing a spec.
Planned topics
- Code-first: write controllers, generate the spec. Fast and always matches the code; the design can become an afterthought.
- Contract-first: write the spec first, then generate or hand-write code to match. Good for reviews and parallel work with client teams; needs discipline to keep code in sync.
- The main risk of both is docs drifting from behavior; check the spec in tests or in CI.
- Commit the spec to the repository so changes show up in code review.
- Many teams use code-first for internal APIs and contract-first for public or partner APIs.
Draft outline details
Demonstration
| Approach | Strength | Risk |
|---|---|---|
| Code-first | Quick, matches code | Weak design review |
| Contract-first | Design agreed early | Code can drift |
Check your understanding
What is the shared risk of both?
Show answer
Docs drifting from actual behavior.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.