Reducing REST Client-Server Coupling
Cost of Knowing Too Much Suppose a client retrieves an order: GET /api/orders/8e2f3a91-6d47-4c8b-9e13-2a7b5c0d4f62 { "status": "placed", "totalPrice": 149.00 } We know the order’s state. But can we cancel it? Pay for it? Where are its items? What request performs each operation? A conventional client learns these details from documentation, an OpenAPI description, or a generated SDK. Its application code might look like this: Order order = api.getOrder(orderId); if (order.status() == PLACED) { api.cancelOrder(orderId); } This client embeds an eligibility assumption: an order in the placed state can be cancelled. It also relies on a predefined operation for submitting the cancellation request. Suppose the business introduces a cancellation deadline: orders may now be cancelled only within 30 minutes of placement. The client-side condition is wrong, and consumers that copied the rule need attention. ...