Data is the main driver behind any application, be it a desktop, mobile, or web app. The developer of an application builds it around how users interact with data. Data keeps track of entities and actions within an app.
Having moved into the mobile app development space since late 2019, I had to answer several questions on how I would structure the apps that I develop. This meant having to actually develop apps, to get the answers.
In software development, there is no other way: you learn by doing. It is not enough to just take courses or go through tutorials. You have to get your hands dirty, and build apps for yourself as if you were building them for an actual client.
One of the challenges I faced, was using a common database for a website and a mobile app. This is an important challenge to solve because, if a client has a website, it is likely that they would require a mobile app as well in due course. And I had to be prepared.
Even if a web app and a mobile app are for the same business concept, the implementation is completely different. Despite their similarities in functionality, completely different technologies have to be used for each.
For instance, I would build a web app, which is essentially an advanced website, using the Laravel Framework. Laravel is a fluent framework based on PHP, and it uses a MySQL Database. On the other hand the mobile app would be built using Flutter with Dart language, and uses an SQLite database.
You can see the problem, right? There are actually two issues. The frameworks are different, which means that the web app cannot directly interact with the mobile app, and vice versa. Even if the communication between frameworks was possible, the databases used by either are incompatible.
What is needed is an approach that allows for the web app and mobile app to use a common database. The ideal is to have the web app as the main database platform, and then build an interface to allow the mobile application to access the same data.
A database is a very important element of a web app or a mobile app. It enables persistent storage of data. When you leave a web app or a mobile app, and then later come back to it, your data is still there, thanks to a database.
Having a separate database for a web app and another for the mobile app would mean that, if you interact with one and then move to the other, you would lose your data across the different platforms, and have to start all over again when you switch over. This is far from ideal.
A database is also essential for storing user data. If there is no common database, it means that users who register on the website or web app, will find themselves not registered on the mobile app, and also vice versa.
The best solution to using common data for a website or web app and mobile app, is the implementation of a RESTful API. REST stands for REpresentational State Transfer. It is a way of creating web services. API Stands for Application Programming Interface.
When creating a REST API, guidelines on how data should be accessed and manipulated on the server are established. These guidelines specify the structure of the commands to execute when requesting and manipulating specific data.
What this means is that data obtained from a MySQL database server, for example, which exists as tables of data, can be transferred as a JSON formatted text string, to the mobile app. The mobile app achieves this by processing the JSON received from the REST response.
This elegantly overcomes the challenge of having two different databases for the web app and the mobile app. Hence the web app can maintain its database, which the mobile app will access and share.
The mobile app can also optionally store data in its own database, for cases where the mobile device is not online, and sync it with the remote database when back online. It should be noted however, that this feature is very complex to implement.
Of course, the RESTful API Also provides a mechanism for the mobile app to write data to the web app database. With that, common data is shared and maintained between the web app and the mobile app.
Want to hear some more from the Webmobyle Blog? Please