Comment on page
Getting data from Firestore
To be able to connect to Firestore from Bravo, we'll need to implement user authentication with Firebase on our app. When a user logs in, an authentication token will be created, and this will allow us to target the Firestore REST API and use it as database for our app (more on this in the next section).
To set this up, we'll need to follow the steps described in the documentation below:
Once we have our Firebase authentication in place, we can create some users, either in the Firebase project itself, or by creating a register screen in the app and creating users there.
After having some users in Firebase, we can start creating our API collection to target Firestore. If you haven't created a Firestore collection yet, you can do that in the
Firestore Databasesection of the Firebase console.
Once we have the Firebase project in place, and we have set up Firebase login in our app project, we can start creating our API collection.
Firestore requires authenticated requests to be able to communicate with its REST API. This means the API requests will contain an auth token from an existing user in our Firebase project. This token will be validated in Firestore when performing an API request.
Therefore, we'll specify an authentication method in our API collection. Once you have created a new collection, go to Collection Settings, and specify the Bearer authentication mode (leaving the token field empty).
Once we do this, we'll be able to create API requests targeting the Firestore collections.
The next step will be creating a sign in request. Although we won't bind this request to any app screen, we'll need it to obtain an authentication token and send authenticated requests against the Firestore API.
[API_KEY]with the value of the Web API Key of our Firebase project. We can obtain it in the Project Settings section of our project, in the Firebase dashboard.
This will be a
POSTrequest. We'll need to add the following body to it:
Now, we'll be able to test the request by indicating the credentials (email and password) of an existing user in our project in
Test Values. If the request is successful, we'll get back a set of values, including our authentication token (
Now that we can get valid authentication tokens, we'll be able to interact with our Firestore collections. In this example, we want to retrieve data from our data collection Users:
Firestore Data Collection
According to Firebase API documentation, to create the Rest API endpoint, you should use the following structure:
YOUR_PROJECT_IDwith your current project ID name.
COLLECTION_NAMEwith your data collection name, in this case,
- 3.Add the URL request to Bravo:
- 4.Don't forget to add
_authorizationin your Test values and add the token you've received from the Sign in request to authenticate the request.
- 5.Click send to receive the data coming from your Firestore data collection!🎉