Spring Boot Engineering / SPRING MVC & REST API / SPR-006

Transfer API

Explore concept graph

Praktik dan verifikasi mandiri

Build: Transfer Controller Contract

Konsep 1 / 3

Map Spring MVC controller methods to the correct path, verb, query parameter and header.

Design GET /transfers/tr-800?verbose=true with an optional X-Trace-Id header and label all three argument sources.

Kasus yang berbeda dari contoh: Different resource ID and different tracing-header name; produce a new signature rather than repeating the sample.

Bukti yang bisa kamu periksa

  • Annotated method signature with a path variable, optional query parameter and optional request header.

Jika ingin lanjut

Define the POST request DTO and response contract, including Location.

Jika terputus: Resume from the difference between path, query and request header bindings.

Konsep 2 / 3

Design a POST endpoint with validated input that returns 201, a resource ID and Location header.

Write a controller-only POST /transfers signature using a different valid amount and demonstrate how a blank sender produces 400 under configured validation.

Kasus yang berbeda dari contoh: Include a field-validation negative case rather than only the happy-path example.

Bukti yang bisa kamu periksa

  • 201 response with resource id and Location; 400 validation example; service method invoked without ledger logic inside controller.

Jika ingin lanjut

Define GET lookup semantics for existing and missing transfer IDs.

Jika terputus: Begin with the difference between status 201 and the Location header.

Konsep 3 / 3

Implement GET 200/404 and keep controller logic limited to HTTP translation.

Add a MockMvc controller-slice test for GET /transfers/tr-999 with mocked service empty, and a separate POST test proving the service is delegated to exactly once.

Kasus yang berbeda dari contoh: Tests use an absent record and mocked service interaction rather than the provided in-memory success lookup.

Bukti yang bisa kamu periksa

  • GET 404 when missing, GET 200 when present, POST 201 with resource ID and Location, 400 for invalid DTO, no business logic inside the controller.

Jika ingin lanjut

Implement actual @WebMvcTest controller tests in a Spring Boot application with a mocked service, and continue to OSX-029 for remote reachability.

Jika terputus: Resume from Optional.of versus Optional.empty and their 200/404 mapping.

Transfer API — POST 201, GET 200/404

Dalam proyek Spring Boot sendiri, implementasikan service interface, DTO request/response, dan controller yang memakai @PostMapping / @GetMapping. Fokus pada kontrak HTTP dan pemisahan tanggung jawab; jangan menganggap ini payment processor produksi.

Latihan manual — jalankan sendiri di lingkunganmu. Kriteria di bawah adalah pemeriksaan mandiri, bukan penilaian otomatis.

Kriteria selesai

  • POST /transfers dengan DTO valid menghasilkan status 201, Location /transfers/{id}, serta body berisi resource ID.
  • GET /transfers/{id} menghasilkan 200 untuk id ada dan 404 ketika service tidak menemukan id.
  • Request DTO memiliki constraint validasi nyata; input tidak valid menghasilkan 400 ketika validation provider aktif.
  • Controller melakukan binding, delegasi service, dan pemetaan status; tidak ada eksekusi transfer atau persistence di controller.
  • Tes MockMvc membuktikan happy path serta negative case 400/404; fixture JDK membuktikan kontrak HTTP tetapi bukan integrasi Spring.
  • Jelaskan pemisahan @PathVariable, @RequestParam, dan @RequestHeader serta alasan memilih masing-masing.

Kriteria verifikasi mandiri

  • Dapat menjelaskan 201 + Location versus 200 dan 404.
  • Dapat menulis signature controller Spring MVC tanpa business logic.
  • Dapat menjelaskan mengapa @Valid membutuhkan constraint dan konfigurasi validasi.
  • Dapat menunjukkan hasil HTTP proof Java 21 dan MockMvc yang berbeda cakupannya.