An API is the bridge between a mobile app and the server. A good design makes the app faster and easier to develop and maintain; a poor design shows up later as slowness, bugs and painful updates. Here are seven rules we follow when building REST APIs for apps.
Why mobile APIs are different
A mobile app cannot be updated the moment the server changes; some users stay on old versions, the network may weaken, and the battery is limited. So the API must be stable, backward compatible and light in data size.
1. Clear resources and consistent names
Name resources with clear plurals: /orders, /orders/{id} and /users/{id}/addresses. Use HTTP verbs for their meanings: GET to read, POST to create, PUT or PATCH to update and DELETE to remove. Consistency lets developers predict paths without checking the docs each time.
2. Understandable status codes and errors
Return the right status code: 200 for success, 201 for creation, 400 for a bad request, 401 for not signed in, 403 for no permission, 404 for not found, 422 for validation failure, 500 for a server error. And return an error message in a fixed format with a code the app can read and text it can show the user, in their language, so the app does not have to guess.
3. API versioning
Put the version in the path, such as /api/v1/. When you need a breaking change, create /v2 and keep the old one working until users update. Remember some will not update for months. Also consider a mechanism that forces very old versions to update.
4. Pagination and filtering
Do not return a thousand items in one request. Use pagination with parameters such as page and per_page or a cursor, and offer filtering and sorting on the server, not in the app. This reduces network and memory load, and it is one of the speed factors we covered in how to keep your app fast.
5. Return only what the screen needs
Huge responses waste the user's data plan and battery. Return the needed fields, and combine related data the screen needs into one request instead of several sequential ones. Design the format so new fields can be added without breaking old versions.
6. Security
- Always use HTTPS.
- Use short-lived access tokens with a refresh token, and never store passwords in the app.
- Check permissions on the server for every request; never trust what the app sends.
- Rate-limit requests to prevent abuse.
- Validate and sanitise all input.
7. Documentation and testing
Document the API in a testable format such as OpenAPI or a Postman collection, so the app and server teams work in parallel. Write tests for critical paths such as payment and sign-up, which we review as part of software testing and QA.
Common mistakes
- Returning 200 with an error message in the body, so the app cannot tell the difference.
- Different field names for the same meaning across endpoints.
- Changing the format without a new version, which breaks published apps.
- Not handling cases where the connection drops mid-request, like payment, and skipping idempotency keys. See payment gateways for apps in the Gulf.
Examples from our work
We have built servers and APIs for projects that depend on them, including the Taggz platform, which is built around APIs and media processing, the Zewail Academy dashboard and the Hozaan app. Learn about our API and backend development and custom software development services. And remember that a good API also serves the admin dashboard. Contact us and we will review your current APIs or design new ones.
Read the next article: Arabic (RTL) app design: eight mistakes to avoid
