Skip to main content
A good API is a promise you can keep for years. This is the map: the conventions, the protocols, and the details that make an API pleasant to use and safe to change.

API Design Best Practices — The Complete Guide

KU
Kiril Urbonas
last month • 4 min read•Updated last month•14 views

A good API is a promise you can keep for years. This is the map: the conventions, the protocols, and the details that make an API pleasant to use and safe to change.

Key takeaways

  • A good API is a promise you can keep for years.
  • This is the map: the conventions, the protocols, and the details that make an API pleasant to use and safe to change.

API Design Best Practices — The Complete Guide#

An API is a contract, and the hard part is that you have to keep it for years while everything behind it changes. Good design is what lets you evolve without breaking the clients who depend on you. This guide is the map: the conventions that make an API predictable, the protocols to choose between, and the operational details (versioning, pagination, limits) that decide whether integrating with you is a pleasure or a support ticket.

The one principle underneath all of it: design for the consumer, not the database. An API that mirrors your tables leaks your internals and traps you; an API that models the domain the client actually cares about stays stable while you refactor freely.

Pick the right protocol#

  • REST is the default for public and web APIs: resource-oriented, cacheable, universally understood. The conventions that matter are in REST API best practices.
  • gRPC wins for internal service-to-service calls that need speed and strict contracts. The trade-offs vs REST are in gRPC vs REST.
  • GraphQL shines when clients need flexible, exact-shape queries over a graph of data. When it beats REST (and when it doesn't) is in GraphQL vs REST.

Most systems end up with more than one: REST or GraphQL at the edge, gRPC between services.

RESTgRPCGraphQL
Best forPublic/web APIsInternal service-to-serviceClients needing flexible, exact-shape queries
PayloadJSON, human-readableProtobuf, binaryJSON
CachingHTTP caching works nativelyNeeds application-level cachingNeeds application-level caching
Browser-friendlyYesNo (needs grpc-web/gateway)Yes
Learning curveLowModerate (schema, codegen)Moderate (resolvers, N+1 pitfalls)

Get the contract details right#

These are the details that generate support tickets when they're wrong:

The conventions that make an API predictable#

  • Use nouns for resources and HTTP methods for actions; return the right status codes (2xx/4xx/5xx meaningfully).
  • Be consistent: naming, casing, date formats (ISO 8601), and error shapes should be identical everywhere.
  • Return structured, actionable errors (a code, a message, a field) so clients can handle them programmatically.
  • Validate input strictly and reject unknown fields; be conservative in what you accept.
  • Make writes idempotent where possible (idempotency keys) so retries are safe.
  • Document everything with an OpenAPI/schema spec that is the source of truth.

The mental model#

Every API decision is really about change over time: a stable contract, explicit versioning, bounded responses, and clear errors are what let you refactor the implementation freely while clients keep working. Design the contract first (the shape clients see), then build to it. When you must break something, version it and give clients a migration path rather than a surprise.

The call we'd make#

Model the domain the consumer cares about, not your schema. Default to REST for public APIs, reach for gRPC between services and GraphQL when clients need query flexibility, and treat versioning, pagination, rate limiting, and errors as first-class from day one. Publish an OpenAPI spec and keep it honest. Each linked guide goes deep on one decision; start from the protocol choice, then nail the contract details that keep integrations from turning into tickets.

Explore topics:DevOps
React

Get the DevOps Troubleshooting Cheat Sheet

Subscribe and get our free one-page reference for the errors that eat an afternoon — CrashLoopBackOff, OOMKilled, Terraform state locks, and more — plus new guides as we publish them.

Share this post
KU

Kiril Urbonas

AI Engineer

560 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.