REST API Development for Mobile Applications
A mobile app hitting the server dozens of times daily but receiving responses with 2–3 second delays due to a poorly optimized API. Traffic grows, users complain about sluggish lists. A typical scenario: an API designed for the web is ported to a mobile client without adaptation. The result is a poor UX and a 30-50% increase in cloud resource bills, costing an extra $1,000–$5,000 per month for a mid-size app. We design REST APIs for mobile applications with the specifics in mind: unstable connections, limited bandwidth, and multiple app versions. Users on the App Store with versions two years old influence architectural decisions from day one. A well-designed API ensures fast UX and reduces traffic by 2-3 times.
Key steps in mobile API design:
- Identify mobile-specific screens and data requirements.
- Design endpoints with minimal payloads.
- Implement cursor-based pagination.
- Set up versioning from day one.
- Build error handling with structured codes.
How to Design Endpoints for a Mobile Client?
A classic mistake is endpoints that return too much data. A profile screen shouldn't load the entire user object with nested relations if only the avatar and name are needed. The BFF (Backend for Frontend) pattern solves this: a separate API layer optimized for mobile screens. An alternative is a fields parameter in the request (?fields=id,name,avatar). For instance, a user list endpoint without BFF might return 50 fields per user; with BFF, only 10 fields are returned, reducing payload size by 80%.
Why Cursor-Based Pagination Is Better Than Offset?
Offset-based pagination (?page=2&limit=20) doesn't work well for real-time feeds — when new entries are added, the offset shifts and users see duplicates. Cursor-based pagination (?after=eyJpZCI6MTIzfQ==) avoids this: the cursor fixes the position, and new entries don't disrupt the order. According to our data, switching to cursor pagination reduces feed loading time by 40% and cuts data usage by 25%. Always return a hasMore flag and nextCursor in the response.
API Versioning
Start with version in the URL (/api/v1/). Mobile apps are not force-updated — 15-20% of users may stay on old versions for months. v1 must run alongside v2 for at least 6-12 months. Ignoring this rule leads to app crashes after changes, something we've seen many times in practice.
Client Networking Layer
Android (Kotlin): Retrofit 2 + OkHttp + Kotlin Coroutines is the established stack. An OkHttp Interceptor for adding Authorization headers, logging (debug only), and retry logic:
class AuthInterceptor(private val tokenProvider: TokenProvider) : Interceptor { override fun intercept(chain: Chain): Response { val request = chain.request().newBuilder() .addHeader("Authorization", "Bearer ${tokenProvider.getToken()}") .build() val response = chain.proceed(request) if (response.code == 401) { tokenProvider.refresh() // retry with new token } return response } } iOS (Swift): URLSession natively or Alamofire. For type-safe requests, use Codable models. Alamofire's RequestInterceptor for automatic token refresh is analogous to OkHttp's Interceptor.
Flutter: The dio package with Interceptor — the same logic. retrofit_dart generates a type-safe client from annotations, similar to Retrofit.
Error Handling
Structured error codes are more important than HTTP statuses for client logic:
{ "error": { "code": "USER_NOT_FOUND", "message": "User with specified ID does not exist", "field": null } } code is machine-readable; the client switches on it. message is for developers, not users. The client displays its own localized strings based on code, not the raw message from the API. Validation errors must include field — the name of the field that failed validation. This allows highlighting the specific field in the form.
| Error Code | HTTP Status | Description |
|---|---|---|
| USER_NOT_FOUND | 404 | User not found |
| VALIDATION_ERROR | 422 | Field validation error |
| TOKEN_EXPIRED | 401 | Access token expired |
Caching and Offline Support
HTTP caching via Cache-Control and ETag reduces server load by 30-50% and speeds up UX. OkHttp supports HTTP cache out of the box with a specified directory and size. But for offline work, a separate layer is needed: Room (Android) or CoreData/SwiftData (iOS) as a local data copy. The Repository pattern separates data sources.
| Mechanism | Application | Benefit |
|---|---|---|
| HTTP cache | Static data (images, lists) | Reduces traffic by 30-50% |
| Local database | Offline mode, profile cache | Works without internet |
Security
- Certificate Pinning:
OkHttp.CertificatePinneron Android,URLSessionDelegatewithdidReceive challengeon iOS. It complicates MITM attacks but requires a certificate rotation plan. According to REST API best practices, this is an essential security measure. - Do not store JWT in
SharedPreferences(Android) orUserDefaults(iOS). UseEncryptedSharedPreferences/Keychain. - HTTPS everywhere, with no exceptions. No
cleartextin production.
Additional security measures:
- OAuth 2.0 with refresh tokens for long-lived sessions.
- Rate limiting on the server side to prevent brute-force attacks.
- Audit log of all requests for tracking suspicious activity.
What's Included in the Work
We deliver end-to-end mobile API development including:
- API documentation (OpenAPI/Swagger specification)
- Client networking layer code with interceptors, error handling, and retry logic
- Caching setup (HTTP cache configuration + local database schema)
- Security implementation (certificate pinning, encrypted token storage, OAuth 2.0)
- Performance optimization (cursor pagination, BFF pattern, response compression)
- 1 month of support post-delivery
With over 8 years of experience and 30+ projects, we guarantee a production-ready API that reduces cloud costs by up to 50% and speeds up client development. Typical timeline: 5-12 days depending on endpoint count. Contact us for a consultation — we provide a guaranteed response within 24 hours.







