-
Value and purpose. An API must solve a concrete task: automate a sale, speed up delivery, provide a payment gateway.
-
Before writing code, define who needs the interface, what operations it must support, and which metrics will indicate success (response speed, error rate, number of connected applications).
-
Each API operation does one clear thing.
-
Several simple methods ("create order", "update status") are better than one all-encompassing one.
-
Resource names (endpoints) reflect the business entity: /orders, /clients, /products.
-
Integrating different systems requires a common language.
-
Create a canonical data model with defined entities (customer, contract, product, order line item) and attributes.
-
Each system will convert its fields into this model and back, avoiding translation chaos. Predictability. APIs must behave consistently: the same date formats (ISO 8601), amounts always with a currency, identifiers without mixed case, page numbers starting from zero or one but uniformly. Versioning.
-
Updates are inevitable: new attributes appear and logic changes.
-
Sound design accounts for versions: v1, v2.
-
Non-breaking changes (for example, a new optional parameter) don't require a new version.
-
Breaking changes are released under a new version number and coexist with the previous ones until everyone migrates. Idempotency.
-
The network is unstable, and requests may be repeated. APIs must ensure that a repeat call with the same parameters won't result in a double charge or a duplicate being created.
-
They use unique operation identifiers and logging.
-
Return an error code, a short description and recommendations. For example, 400 Bad Request: field 'email' is missing — with a link to the documentation.
-
Generic "something went wrong" messages without details are unacceptable.
-
Security and privacy. APIs handle user data.
-
You must protect channels (HTTPS), restrict access on the least-privilege principle, encrypt stored keys, mask personal data in logs, audit access and meet the requirements of FZ-152 and GDPR. Observability. Think about logs, metrics and tracing from the very start. Every request gets a unique ID that travels through all services.
-
This makes it possible to quickly pinpoint a failure.
-
Metrics include response time, error rate, queue depth and retry count.