API Contracts

API contracts are the promises your service makes to clients. They define the shape of success responses, the meaning of status codes, the structure of errors and the rules for evolving the interface safely over time.

Stability matters more than cleverness

A contract should be predictable before it is elegant. Consistent response envelopes, stable field names and machine-readable error objects reduce friction for frontend clients, integrations and tests.

funksjon api_ok(data: tekst) -> tekst {
    returner "{\"ok\":true,\"data\":" + data + "}"
}

Versioning and change control

Breaking changes should be intentional and visible. Add new fields gradually when possible. Avoid changing types or meanings silently. That discipline keeps the API useful for multiple clients at once and makes releases safer.

The best companion chapters here are web and API and integrations.