Skip to content
Ameen Abozaid
Planned lessonJNR-021-L04

Code-first vs contract-first

  • Lesson 4 of 5
  • Junior
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

ApproachStrengthRisk
Code-firstQuick, matches codeWeak design review
Contract-firstDesign agreed earlyCode 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.