We mainly use Firebase for our RealTime DB. It is a platform for mobile and web apps.
The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. All of your clients share one Realtime Database instance and automatically receive updates with the newest data.
In the structure above, we can make an efficient listener for our users. The idea is that they can only see the updates of their order based on their mobile numbers.
transactions
- <ROOTOBJECT>
This is a static root object to group the transactions.999999999
- <MOBILENUMBER>
This is the mobile number user use to order an item489771923346567800
- <TRACKING>
This is the tracking number for that order.IN-TRANSIT
- <BODY>
This is the order status.The basic write operation through the REST API is PUT
. Using PUT
, we can write a string, number, boolean, array or any JSON object to our Firebase database. In this case, we'll pass it an object:
Example:
curl -X PUT -d <BODY>
"https://<DATABASEAPP>.firebaseio.com/<ROOTOBJECT>.json"
Since the object we will update is one layer deeper, we will need to map it as we are routing to the pages.
curl -X PUT -d <BODY>
"https://<DATABASEAPP>.firebaseio.com/<ROOTOBJECT>/<MOBILENUMBER>/<TRACKING>.json"
It will be then:
curl -X PUT -d "\"IN-TRANSIT\""
https://<DATABASEAPP>/transactions/9999999999/489771923346567800.json
NOTE: authToken
will be passed to restrict DB access.
curl -X PUT -d "\"IN-TRANSIT\""
https://<DATABASEAPP>/transactions/9999999999/489771923346567800.json?auth=D5S9zGA8SsN9J28KMUlCrPGrVhHkXiBjSRSdQ0Tc
This token will be implemented in the staging platform only. This will change once deployed in production and should be saved on your
env
orconfig
file.
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
An FCM implementation includes two main components for sending and receiving:
You can send messages via the Admin SDK or the HTTP and XMPP APIs. For testing or for sending marketing or engagement messages with powerful built-in targeting and analytics, you can also use the Notifications composer.
We will be using HTTP and XMPP APIs.
curl -X POST --header "Authorization: key=<SERVER KEY>" --Header
"Content-Type:application/json" https://fcm.googleapis.com/fcm/send -d
"{\"to\":\"<BROWSER TOKEN>\",
\"data\":{
\"notification\":{
\"body\": \"<BODY>\",
\"title\":\"<TITLE>\",
\"data\": {
\"url\":\"<URL>\"
}
}
},\"priority\":10}"