Building Reliable APIs
backendapi
A practical checklist for APIs that are easy to operate and hard to break.
Good APIs feel boring in production. That usually means clear contracts, predictable errors, and a small set of habits you never skip.
Keep handlers thin
Route handlers should parse input, call domain logic, and shape the response. Business rules belong in plain functions you can unit test without spinning up HTTP.
Fail with intent
- Use stable error codes clients can branch on
- Return validation details without leaking internals
- Log once with request context, then respond
Example shape
type ApiError = {
code: "VALIDATION" | "NOT_FOUND" | "INTERNAL";
message: string;
details?: unknown;
};Start simple, keep the contract versioned in your head (and eventually in OpenAPI), and optimize only after you measure.