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

Suggested study path · Step 1 of 5 · G1

Transfer API Spec

Explore concept graph

Materi

Problem: frontend membutuhkan API transfer dengan request, response, status, dan error yang stabil, walaupun implementasi controller, service dan database bisa berubah.

Mulai: tulis kontrak tiga operasi terlebih dahulu: POST /transfers, GET /transfers/{id}, dan GET /accounts/{id}. Jangan membuat controller sebelum semua respons observable disepakati.

Peta konsep statis. Ikuti alur teks dari atas ke bawah.
Bearer-authenticated client
         |
         +--> POST /transfers
         |       CreateTransfer JSON
         |       201 Created + Location: /transfers/tr-001
         |       Transfer JSON (status=PENDING)
         |
         +--> GET /transfers/{id} --> 200 Transfer / 404 missing
         |
         +--> GET /accounts/{id}  --> 200 Account / 404 missing
         |
         +--> 400 invalid input / 401 missing auth (+ challenge)
         +--> 403 forbidden / 409 reference conflict / 500 server
                  |
             application/problem+json
                  |
        V1 required fields are preserved
                  |
          V1.1 optional description

Resource dan response matrix

Endpoint Success Kegagalan yang dimodelkan
POST /transfers 201 + Location + Transfer 400, 401, 403, 409, 500
GET /transfers/{id} 200 + Transfer 401, 403, 404, 500
GET /accounts/{id} 200 + Account 401, 403, 404, 500

Kebijakan lab: 409 berarti clientReference sudah digunakan. Itu keputusan desain yang harus benar-benar diimplementasikan sebelum dipakai; dokumen tidak membuktikan idempotent retries, deduplikasi transaksi atau pemrosesan tepat sekali.

Contoh POST request

POST /transfers HTTP/1.1
Authorization: Bearer <demo-token>
Content-Type: application/json
Accept: application/json

{
  "clientReference": "client-ref-001",
  "sourceAccountId": "acc-01",
  "destinationAccountId": "acc-02",
  "amount": "125000.00",
  "currency": "IDR"
}

Contoh 201 Created

HTTP/1.1 201 Created
Location: /transfers/tr-001
Content-Type: application/json

{
  "transferId": "tr-001",
  "clientReference": "client-ref-001",
  "sourceAccountId": "acc-01",
  "destinationAccountId": "acc-02",
  "amount": "125000.00",
  "currency": "IDR",
  "status": "PENDING",
  "createdAt": "2026-11-06T08:00:00Z"
}

Contoh ini memodelkan response; tidak ada bearer token sungguhan, service di-deploy, atau database yang diakses.

Konsep 1 / 3

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

Clients depend on paths, methods and payload formats that should survive controller refactors and database schema changes.

Mulai dari sini

Write down the exact three canonical method/path pairs before drafting DTOs.

Intuisi utama

The API contract is the observable boundary: POST /transfers creates a resource; GET /transfers/{id} and GET /accounts/{id} retrieve representations. Resource models are not the same thing as database tables.

SYS-008 defines POST /transfers, GET /transfers/{id}, and GET /accounts/{id}. POST requires clientReference, sourceAccountId, destinationAccountId, amount as a decimal string and currency IDR/USD. A successful POST returns 201 with Location: /transfers/tr-001 and the new transfer representation. The server assigns transferId and createdAt; a client must not assume synchronous settlement from 201. GET may return 200 with the requested representation or 404 when absent. The example uses bearer authentication and clientReference conflict as an explicitly designed policy, not a guarantee of real idempotency or fraud checks. Avoid returning binary floating-point for monetary amounts.

Contoh bertahap

A client needs to create a transfer, fetch it by ID, then query the source account without knowledge of the underlying database.

  1. Define three paths with HTTP methods and stable identifiers.

    Mengapa: Resource naming separates client-visible contract from backend persistence structure.

    Hasil yang diharapkan: POST transfers and two GET-by-ID routes exist in the spec.

  2. Write POST request as typed JSON, with decimal amount encoded as string.

    Mengapa: Floating-point serialization should not silently change the example monetary quantity.

    Hasil yang diharapkan: source/destination IDs, clientReference, amount and currency are declared required.

  3. Specify 201 with Location and a Transfer representation.

    Mengapa: Client must learn the URI of the created transfer resource.

    Hasil yang diharapkan: HTTP Location points to /transfers/tr-001, echoed by transferId in response.

Konsep 2 / 3

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

Retry logic, authentication prompts and support diagnostics depend on clients receiving the right status class without leaked internal information.

Mulai dari sini

Make a two-column table of authentication failure versus authorization failure.

Intuisi utama

HTTP status communicates protocol outcome; problem+json communicates typed, safe error context. 401 challenges authentication, 403 rejects permitted access, 409 signals state conflict.

Choose 400 for malformed/invalid transfer input, 401 with WWW-Authenticate: Bearer for absent/invalid credentials, 403 for an authenticated caller lacking permission, 404 for absent transfer/account resources, 409 for a clientReference already used under the example API policy, and 500 for an unexpected server failure. RFC 9457 error body uses type, title, status, detail and optional instance; if status is present it must match the HTTP line. The exact business scenario assigned to 409 is a proposed policy, not a universal status rule. Never return stack traces, credentials, raw SQL or hidden account details in client-visible problems; clients should parse type and status rather than human-readable detail. 401 vs 403 must not be conflated.

Contoh bertahap

A client submits a transfer with missing required amount, then retries with invalid Bearer credentials, then uses an existing client reference.

  1. Classify invalid JSON/body under 400 and include a typed Problem Details body.

    Mengapa: Malformed client input is different from an internal failure.

    Hasil yang diharapkan: HTTP 400 matches problem.status 400, without sensitive internal detail.

  2. Return 401 and WWW-Authenticate for absent/invalid bearer credentials; 403 for valid but unauthorized identity.

    Mengapa: Authentication and authorization have different client recovery paths.

    Hasil yang diharapkan: A 401 challenge exists; the 403 example contains no credential leak.

  3. Return 409 for duplicate clientReference per explicit policy, 500 for unexpected internal errors.

    Mengapa: A state conflict is distinct from server unavailability.

    Hasil yang diharapkan: Problem type and HTTP status are stable; 500 detail remains generic.

Konsep 3 / 3

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

A release that removes or retypes a required response field can break existing clients even when server-side code compiles and endpoint tests stay green.

Mulai dari sini

Write the original required TransferResponse field names and types from the OpenAPI schema.

Intuisi utama

A versioned contract is a set of observable promises. Add optional response metadata without changing previously required fields; verify consumers before declaring compatibility.

The first transfer response requires transferId, sourceAccountId, destinationAccountId, amount, currency, status and createdAt. A proposed V1.1 adds an optional description string only: old fields and their types remain identical. Removing amount or replacing decimal string with a JSON number is breaking for the older contract. This lab includes an explicit older-client consumer that reads the known required fields and ignores the optional added description. That one fixture is design-time compatibility evidence only, not a proof that *every* real consumer tolerates unknown fields. Review idempotency, security, logging, retries, backward compatibility and server enforcement with a separately implemented service; the spec does not execute Spring MVC or banking transactions.

Contoh bertahap

An API team wants to add an optional display description to an existing transfer response without breaking the original client.

  1. Keep required TransferResponse properties unchanged and add optional description in V1.1.

    Mengapa: An old client must still find the required identifiers, amount string and currency.

    Hasil yang diharapkan: The same old required keys and types remain valid in both examples.

  2. Run the standalone contract fixture against baseline and optional-field evolution examples.

    Mengapa: A design-time test catches local schema/type drift and a deliberately breaking change.

    Hasil yang diharapkan: Old-reader check passes for additive description and rejects amount-as-number.

  3. Document the proof boundary and real consumer test required before deployment.

    Mengapa: A static contract cannot guarantee all downstream clients accept unknown fields.

    Hasil yang diharapkan: Review sheet lists consumer validation and Spring integration as follow-up evidence.

Sumber resmi

Sumber

Cross-domain connections

Curated relationships for this unit at G1. Proposed edges are suggestions, not prerequisites.

Concept connectionsG1 · 4 visible concepts · 4 curated links
100%

Dashed = proposed relationship; solid = reviewed connection. Only reviewed prerequisites constrain a learning path. Keyboard and text links remain available.