This tutorial will show you how to create a native mobile app from scratch using Supabase as the back-end database and Draftbit as the mobile app. Draftbit is an interactive visual development platform based on open-source frameworks and libraries. So you will be using open-source React Native to build your mobile app.
Using a REST API, you can integrate your Draftbit app to any back-end-as-a-service (BaaS) platform like Backendless, Xano, or Contentful. If you want to know more about how to do that, you can refer to these guides.
This tutorial is for you if you already have a Supabase back-end and are very familiar with it. But if you do not have a Supabase account, you can create one here. Supabase makes creating endpoints a very easy task, and I will show you what API endpoints you need to use from Supabase for data manipulation.
In this tutorial, we will show you how to:
Now let’s move on to setting up your data and API in Supabase.
First of all, in your Supabase account, you need to create a new database. Here’s how you can do that:
Select the database panel from your project dashboard, select the database panel, click on the Table Editor, and add New Table. For this tutorial, we will add a new data table called Groceries with two columns and add the following data for the two columns.
Now we have got our table with some data in it. To access the data in this table, we need to use the REST API that Superbase provides. To connect the API in the Draftbit app, you need the following two values:
You can all these unique values from the API button on the left menu bar of your Supabase’s dashboard. Let’s go there and do the following.
If you don’t have a Draftbit account, create one here. Once you’ve got your account set up, Create a New App. For this demo, you can select Start From a Blank App and proceed to the Builder.
First, add Authorization and apikey headers to your Draftbit app. To do that, go through the following steps.
Next, do the following steps to add the Supabase API information in your Draftbit app.
Now that we’ve got the Supabase base service connecting to a Draftbit app, we can utilize all of Supabase’s HTTP methods to access and manipulate data.
In the next section, we will GET a list of data, GET an individual item from the Supabase database and POST a new item to it.
In a blank screen in Draftbit, add the following components as nested components.
After adding them, your Layout Tree will look like the following screenshot.
Initially, you will see an empty or a loading screen because we haven’t populated the components’ data. We will do that in the next sections.
Now, open the Data menu from the left-hand navbar as you did previously, and do the following steps in the popup modal as illustrated from the below gif.
If you did the above steps correctly, you should get a 200 OK response with data in your schema in Supabase as a JSON object. If you got a bad response, make sure that you copied & pasted your Base URL and Table Name paths correctly and that your data table has actual data in it. After creating the endpoints, Save & close the modal.
Next, we need to map the GET request’s response to the components on your screen in Draftbit. You can see how to do that in the GIF below.
Now all is set to map data variables to the text component.
If you did this correctly, you should see the screen populated with fetched data from your endpoint from the preview.
Again add a new blank screen in Draftbit, add the following components as nested components.
After adding them, your Layout Tree will lo like the following screenshot.
Next, open the Data menu from the left-hand navbar as you did previously, and do the following steps in the popup modal as illustrated from the below gif.
If you did the above steps correctly, you should get a 200 OK response with exactly one result for the test value you input from your schema in Supabase as a JSON object. If you got a bad response, make sure that you copied & pasted your Base URL and Table Name paths correctly and that your data table has actual data in it. After creating the endpoints, Save & close the modal.
Next, we need to map the GET request’s response to the components on your screen in Draftbit. You can see how to do that in the GIF below.
After creating it, you should see the same JSON response in the Fetch Preview when testing the GET endpoint. Now all is set to map data variables to the text component.
You should see a single item populated with fetched data from your endpoint like in the following figure if you did this correctly.
Now that we are familiar with fetching data from a Supabase back-end into our mobile app front-end let's try adding a new record in our Supabase table.
For this section, you need to use at least one component that accepts user input and has a Field Name prop to POST data using Supabase REST API. You can use one of the following components for that.
In addition, you need a Touchable component like a Button to attach the POST action. After you have created these components, we will create our POST endpoint.
Now, open the Data menu from the left-hand navbar as you did previously, and do the following steps in the popup modal as illustrated from the below gif.
{
"Item": {{item}},
"Price": {{price}}
}
Set test values for your two data variables.
Once you follow the above steps, you should get a 200 OK response with exactly the new record as a JSON you have entered for your schema. In case you get a bad response, make sure that you copied & pasted your Base URL and Table Name paths correctly and that your data table has actual data in it. After creating the endpoints, Save & close the modal.
Now we have a working POST request. Let’s map its response to the components on your screen in Draftbit. You can see how to do that in the GIF below.
After completing the above steps, you should see the list view populated with fetched data, including the newly added item from your endpoint if you did this correctly.
Now we know how to enter a new record to the Supabase database from our mobile app front-end. Let’s try updating an existing record there. Open the Data menu from the left-hand navbar, and do the following steps in the popup modal as illustrated below.
{
"Item": {{itemName}},
}
If you follow the above steps correctly, you should get a 200 OK response with the updated record as a JSON response. In case you get a bad response, make sure that you copied & pasted your Base URL and Table Name paths correctly and that your data table has actual data in it. After creating the endpoints, Save & close the modal.
Now we have a working PATCH request. Let’s map its response to the components on your screen in Draftbit. Like you created text inputs to enter data, create one text input and a Touchable Component to send updates. The below gif shows you how to continue with the rest of the steps.
After completing the above steps, you should see the list view populated with the updated data,
Finally, we will delete an existing record in our Supabase database. Open the Data menu from the left-hand navbar,
If you correctly follow the above steps, you should get a 200 OK response with an empty JSON response. In case you get a bad response, make sure that you copied & pasted your Base URL and Table Name paths correctly and that your data table has actual data in it. After creating the endpoints, Save & close the modal.
As you did in the previous section, you can add a button to bind the delete endpoint. If you have done the configurations successfully, you will see no record in your Supabase database.
How to do CRUD operations through your Draftbit mobile app is important for interacting with your Supabase database. This tutorial taught you how to GET a single item and a list of items from a Supabase back-end to your Draftbit app. Also, you learned how to add a new item, update an item and delete data in Supabase through the Draftbit front-end.