Designing REST APIs your web and mobile clients will thank you for
An API is a product with its own users: the developers building against it. Treat it that way and the whole system gets easier to change.
Get the basics boringly consistent
- Nouns for resources, plural, lowercase —
/invoices,/invoices/42/line-items. - One pagination style everywhere (cursor for feeds, offset for admin tables) and document it once.
- One error envelope: an HTTP status, a stable machine
code, a humanmessage, and adetailsmap for field errors. - Dates in ISO 8601 UTC. Money as integer minor units plus a currency. Never floats.
Versioning
Put the version in the URL (/v1/). Add fields freely; never remove or repurpose one within a version. When you must break, ship /v2/ and run both for a deprecation window.
Make the happy path one call
If a screen needs a resource plus three related things, let the client ask for them with an include= parameter rather than making four round trips on a mobile network.
Auth that fits clients
Short-lived access tokens, a refresh mechanism, and scopes that map to real product permissions. Rate-limit per key and return the limit headers so clients can back off.
Filtering, sorting and search
Pick one convention and use it everywhere: for example ?status=paid&sort=-created_at. Whitelist the fields that can be filtered and sorted, both for performance and to avoid exposing columns by accident. For full-text search, a dedicated q parameter is clearer than overloading filters.
Idempotency for anything that costs money
Mobile networks drop requests after the server has processed them, so clients retry. If "create payment" or "place order" runs twice, the customer is charged twice. Accept an idempotency key header on these endpoints and return the original result for a repeated key.
Documentation that stays true
Maintain an OpenAPI description alongside the code and generate reference docs from it. Include real example requests and responses, error codes and the meaning of each status. Contract tests in CI catch the moment code and documentation drift apart.
Designing for mobile clients
- Old app versions stay installed for months — never break a field they depend on.
- Return only what the screen needs; large payloads are slow on mobile data.
- Support conditional requests (ETags) so unchanged data isn't downloaded again.
- Send timestamps and let the client format them in the user's locale.
Observability
Log a request ID on every call and return it in a response header, so a user's support ticket can be traced to the exact request. Track latency and error rate per endpoint, not just overall.
Talk to us
Need an API built or cleaned up? See API development & integrations, or get a free quote — we reply within one business day.