How to design APIs for mobile clients
· Category: API & REST
Short answer
Mobile APIs must account for unreliable networks, limited bandwidth, and battery constraints by minimizing payload size and request count.
Steps
- Implement field selection so mobile clients request only necessary data.
- Compress responses with gzip or brotli to reduce transfer size.
- Design coarse-grained endpoints that return aggregated data in fewer calls.
- Support pagination and caching to handle large datasets gracefully.
- Version APIs to allow mobile app updates to align with backend changes.
Tips
- Use binary serialization formats like Protocol Buffers for extreme efficiency.
- Implement request coalescing to batch multiple client needs.
- Handle offline scenarios with retry queues and sync endpoints.
- Optimize image and media delivery through CDNs with adaptive compression.
Common issues
- Chatty APIs causing battery drain from frequent radio activation.
- Large JSON payloads leading to slow rendering and high memory use.
- Breaking changes forcing users to update apps immediately.
- Lack of retry-friendly idempotency causing duplicate actions on poor networks.
Example
curl -X GET https://api.example.com/users -H "Accept: application/json" -H "Authorization: Bearer $TOKEN"
This curl command demonstrates a standard GET request with headers for content negotiation and bearer token authentication.