System Design Engineering / ARCHITECTURE BOUNDARIES & API DESIGN / SYS-008

Transfer API Spec

Explore concept graph

Latihan soal

Desain failure: jangan tertukar 400 / 401 / 403 / 409 / 500

Status Kapan digunakan pada kontrak latihan Yang dilakukan client
400 JSON/field amount atau ID tidak valid Perbaiki payload
401 Bearer token hilang atau invalid Ikuti WWW-Authenticate challenge
403 Sudah authenticated, tidak berhak mengakses akun Jangan otomatis mengulang dengan token identik
404 Transfer/account ID tidak ditemukan Periksa resource ID; kebijakan concealment harus konsisten
409 clientReference telah dipakai (kebijakan lab) Selidiki konflik; jangan membuat referensi baru secara buta
500 Server mengalami kondisi tidak terduga Tampilkan pesan aman; jangan tampilkan stack trace

Contoh problem detail untuk konflik:

HTTP/1.1 409 Conflict
Content-Type: application/problem+json

{
  "type": "urn:cs101:problem:reference-conflict",
  "title": "Client reference conflict",
  "status": 409,
  "detail": "The clientReference is already in use."
}

Untuk 401, gunakan WWW-Authenticate: Bearer realm="transfers" beserta status 401. urn:cs101:problem:... adalah identifier contoh yang tidak dirancang untuk dereference. Konsumen memakai type dan status, bukan parsing dari detail yang bisa berubah.

OpenAPI 3.1.1 — spesifikasi yang dapat diperiksa

Kontrak JSON lengkap: contracts/SYS-008/transfer-api.openapi.json di repository. File itu berisi ketiga path, schema CreateTransfer/Transfer/Account/Problem, parameter ID, security scheme Bearer, response examples dan status/error matrix.

Jalankan pemeriksaan lokal pada Node 24:

node generation/fixtures/SYS-008/contract-review.mjs

Output yang diharapkan:

contract-paths=3
contract-status-matrix=passed
contract-problem-details=passed
contract-backward-compatible=passed
contract-runtime=not-executed

Checker ini membaca file OpenAPI yang ditrack dan memeriksa subset kontrak dan contoh: tiga operasi, 201/Location, tipe amount string, 401 challenge, kesesuaian status Problem Details, dan perubahan opsional. Ini bukan validator lengkap spesifikasi OpenAPI, bukan HTTP integration test, dan bukan bukti Spring MVC sudah sesuai kontrak.

Konsep 1 / 3

Describe three transfer/account resources with stable request and response shapes and correct POST/GET semantics.

Coba prediksi atau perbaiki

Why does POST /transfers return 201 with Location rather than only return 200 and no resource identifier?

Kalau jawabanmu berbeda

Kesalahan yang mungkin: Treating an HTTP resource path as a database table name or a successful POST as completed settlement.

Mengapa tidak bekerja: Resource representations can differ from storage; HTTP 201 only reports creation of a resource.

Coba perbaiki: Model client-visible IDs, content type and Location independent from database schema and business-state transitions.

Periksa hasil sendiri

Hasil yang diharapkan: The specification has three operations, required DTO fields, and 201/Location consistent with a created transfer.

Kalau berbeda: Inspect openapi.json paths and response objects; compare example transferId with the Location path.

Konsep 2 / 3

Select and justify 201, 400, 401, 403, 404, 409 and 500 with a consistent RFC 9457 error envelope.

Coba prediksi atau perbaiki

Authenticated caller lacks permission for account acc-02. Should the API return 401 with no challenge or 403?

Kalau jawabanmu berbeda

Kesalahan yang mungkin: Returning 401 for every forbidden request or using 500 for malformed client input.

Mengapa tidak bekerja: Clients cannot distinguish reauthentication from permission denial or fix input errors consistently.

Coba perbaiki: Match 401/403/400/409/500 semantics and require safe problem+json status/title/type fields.

Periksa hasil sendiri

Hasil yang diharapkan: The OpenAPI contract includes six required status choices plus 404 retrieval, with 401 explicitly carrying Bearer challenge.

Kalau berbeda: Check RFC 9110 definitions and RFC 9457 before assigning status; update examples and schema together.

Konsep 3 / 3

Distinguish additive response changes from breaking schema/required-field changes and review with concrete older-client expectations.

Coba prediksi atau perbaiki

Is changing amount from "125000.00" to 125000 a backward-compatible evolution if an older client expects a decimal string?

Kalau jawabanmu berbeda

Kesalahan yang mungkin: Assuming adding any field or changing a JSON type is always backward-compatible without consumer knowledge.

Mengapa tidak bekerja: Strict client validators can reject unknown fields, and retyping required values can break parsers.

Coba perbaiki: Treat additive optional changes as candidates for compatibility, validate actual clients, and keep required field names/types unchanged.

Periksa hasil sendiri

Hasil yang diharapkan: The standalone contract checker passes the optional description example but rejects an amount-as-number mutation.

Kalau berbeda: Inspect schema required arrays, public type definitions and actual older-client code; restore old types before review.

Lima soal design review

Jawab tanpa melihat pembahasan dulu. Kamu bisa memperbaiki jawaban dan mencoba lagi. Kuis ini latihan mandiri dan tidak menyimpan skor atau progres.

POST /transfers berhasil membuat tr-001. Respons paling tepat jika resource baru dapat diambil melalui GET?
Client mengirim Authorization token yang tidak valid. Respons RFC 9110 yang harus dikirim?
Pemilik token valid mencoba mengakses transfer yang tidak berizin. Pilihan status umum?
API mengembalikan status HTTP 409 tetapi body problem+json berisi status: 500. Apa kesalahannya?
Versi API baru menambah description opsional tetapi tidak mengubah field lama. Klaim kompatibilitas yang tepat?