Java · Advanced level

Advanced level · Module 6: Java Capstone Project · Lesson 3 of 5

Implementing the API

Build the service and controller layers for every story, with validation and consistent errors.

In this lesson you will

  • Implement services and endpoints from the contract
  • Enforce business rules with clear exceptions and status codes

Key concepts

service rulescontroller mappingerror formatcontract conformance

The lesson

Implement one user story at a time, end to end: service method with its rules, controller endpoint, validation and tests. A finished, tested story is worth more than five half-built ones.

Business rules such as 'appointments only in clinic hours' and 'no cancellation after the appointment time' belong in the service and are signalled with specific exceptions that map to status codes.

Check each endpoint against the contract: path, method, request and response shape, status codes. Any difference is either a bug or a contract change that must be documented.

Step by step

  1. Implement the booking story end to end.
  2. Implement listing, updating and cancelling.
  3. Map each rule violation to the agreed status code.
  4. Compare every endpoint with the contract.

Practice activity

Complete milestone 3: all endpoints implemented according to the contract.

Expected result: Every story works through the API, and the instructor's contract check finds no differences.

Check your understanding

  1. Why implement one story end to end before starting the next?

    Show answer

    Each story is then finished and tested, which reduces risk and shows progress.

  2. Where should 'no booking outside clinic hours' be enforced?

    Show answer

    In the service layer, with a specific exception mapped to an error response.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.