freecoding.school100% FREE · NO SIGNUP
Gateway RidgeISSUE #30 of 35

api design · the principle of least surprise

Gateway GusVSTimeout Titan
Gateway Gus saysThe principle of least surprise: be consistent so developers can guess your API correctly.

A great API is predictable. Use consistent naming (plural nouns, snake_case or camelCase — pick one), consistent error shapes, consistent date formats (ISO 8601), and consistent pagination across every endpoint. When one endpoint behaves like the others, developers learn your API once and guess the rest right. Surprises cost integration time and trust.

Power-ups you unlock

Timeout Titan attacks — common mistakes

Boss battleSpot three inconsistencies that would make an API surprising.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>surprising: /users (camelCase) + /blog_posts (snake)
            dates as epoch here, ISO there
consistent: one casing, one date format, one error shape</pre></body></html>
▶ Open the interactive comic issue
‹ Api Design · Pagination · Filtering · ExpansionApi Design · Evolving Without Breaking ›