API Design

Overview

API design defines how services expose capabilities to clients. Good API design improves reliability, discoverability, and long-term compatibility.

Design Principles

sequenceDiagram participant Client participant API participant Service Client->>API: GET /v1/orders/1452 API->>Service: Fetch order Service-->>API: Order data API-->>Client: 200 OK + JSON

Practical Example

GET /v1/orders/1452 Accept: application/json
{ "orderId": "1452", "status": "SHIPPED", "total": 149.90, "currency": "USD" }

Error responses should stay consistent:

{ "error": { "code": "ORDER_NOT_FOUND", "message": "Order 1452 was not found", "traceId": "a18d9f" } }

Common Pitfalls

Key Takeaways