![]() Even if you force-close the app and reopen it, it uses the local data. From that point on, the app uses the data that’s stored in Realm. When opened for the first time, RCurrency uses a REST API to retrieve exchange rates, and stores the data in Realm. You choose a base currency and a list of other currencies you want to convert between. It’s intended for uses such as converting currencies when traveling. The RCurrency app is a simple exchange rate app. Realm Sync then makes that data available locally on every user’s mobile device-without the need for any additional API calls. A more scalable approach is to have your backend Realm app fetch the data from the API and store it in Atlas. That can lead to issues as your user base grows. Many APIs throttle your request rate or charge per request. If you need to update cloud data when offline, then I’d strongly recommend you consider MongoDB Realm Sync. Writing an offline-first app that needs to reliably update cloud data via an API is a far more complex affair. This app only reads data through the API. ![]() Is Using the API from Your Mobile App the Best Approach? This article shows how the RCurrency mobile app fetches exchange rate data from a public API, and then caches it in Realm for always-on, local access. This leads to higher availability, faster response times, and reduced network and battery consumption. It’s easy to make a call to a REST API endpoint from your mobile app, but what happens when you lose network connectivity? What if you want to slice and dice that data after you’ve received it? How many times will your app have to fetch the same data (consuming data bandwidth and battery capacity each time)? How will your users react to a sluggish app that’s forever fetching data over the internet?īy caching the data from API calls in Realm, the data is always available to your app. While other technologies are growing (e.g., GraphQL and MongoDB Realm Sync), REST APIs are still prevalent. When building a mobile app, there’s a good chance that you want it to pull in data from a cloud service-whether from your own or from a third party. Note that this post was originally published at Build Offline-First Mobile Apps by Caching API Results in Realm. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |