Nested lists (list > list > detail page) with Xano
In this tutorial, we'll build an app inspired in a famous service used by travelers and digital nomads, with information about some of the most popular cities in the world.
To build it, we'll use Xano, a powerful no-code backend tool, that will allow us to define the database for the app, and build the API endpoints that will be used later to connect Bravo and the database.
✨ Features
List of all the cities, with screens displaying information about each one of them.
Screen for the different regions in the world, with a list of the cities that belong to that region (List of regions → list of cities in the region → screen with city details).
Customizable no-code backend, ability to define the API endpoints.
💎 Resources
Design file: Figma
This Figma file is Bravorized and ready to be imported into Bravo. If you want to customize it, duplicate it on Figma and make all the edits you wish.
🏗 Creating the backend with Xano
In the first part of the tutorial, we'll generate the database with Xano, and we'll define the API endpoints that will be used to connect later with Bravo. You'll need to create a Xano account here.
Creating the database structure
First, we'll create two tables in Xano: Cities and Regions. In the Cities table, we'll store all the information about individual cities: population, monthly living cost, winter and summer average temperature. In the Regions, we'll store the names of the world regions, and a picture to use in the app to identify them.
We'll first create a table with the cities. In the database
tab in Xano (on the left), we'll click Add Table
, and name it Cities. Two fields are already created in the table: id
and created_at
. We'll add the following fields (by clicking the +
icon):
city (text field)
population (integer field)
living_cost_euros (integer field)
winter_temp (integer field)
summer_temp (integer field)
picture (storage → image metadata). We'll add a header picture in the screen for each city.
We'll add the following sample cities in the database:
We'll upload one picture per city as well. In the table, for each city, click on the Upload
button in the "picture" field. You can upload any picture you wish, we used Unsplash to search for license-free images from each city.
In the Xano free plan, the uploaded images will be watermarked. More information about the Xano Plans here.
Now, let's move to the table with the world regions. We'll add a table with the name "Regions", and then create these two fields.
region (text field)
picture (storage → image metadata), we'll use it to display later in the app the list of regions.
Finally, we need an extra field in this table. We'll use this to establish the relation between the Regions and the Cities tables, by saying which cities belong to each region. This field will have a Table Reference
type. In "Choose Database Model", we'll select the Cities table. Now a field called cities
has been created. We also need to make this field a "list", as there can be several cities related to a single region. We'll click on the "cities" field header, and in the menu that pops up, select Change Type
. Then, we'll select list
structure, instead of "single".
After having the structure set up, we'll complete the table with the following data. Remember that in the "cities" field we'll create references to the different cities we created in the "Cities" table.
Creating the API endpoints
Once we have all the data, it's time to create the API endoints! These will be the ones that we call from Bravo to feed our app with the data we just generated.
Go to the API dashboard on the left panel in Xano. In the top right, we'll click on Add API group
. Put the name of "World Cities", and write a short description if you wish. You'll see that no endpoints are created for now.
First, we'll create an endpoint to get all the records of the Cities table. Click on Add API endpoint
on the top right. Select CRUD Database Operations
, Cities
table, and finally GET
. This will create an endpoint that will be targeted with a GET request, and will return all the data in the Cities table. In the last step, put a description if you wish, and click "Save".
We have created our first API endpoint! After, we'll go to a screen that displays details for this endpoint. These details correspond with the request lifecycle: the steps that Xano will complete once a request targeting this endpoint is received. Here, we'll specify how to treat the data contained in the request, and how to construct the response message.
The first step is to select the inputs that we want our endpoint to accept. As this GET request will always retrieve all the data for the cities, no inputs will be accepted.
Therefore, we'll advance to the second step, called "Function Stack", where we'll configure how to process the inputs we selected in the previous step, and what processing do we want to do with them and the data living in our database. As this endpoint will just return all the data, we just want to select all the rows from the Cities table. We can see how Xano already configured a query to do this: "Query All Records from Cities".
We'll can test the endpoint by clicking on Run & Debug
on the top right, and we'll see how we get all the data from the Cities table returned.
Next, we'll create the following 3 endpoints:
GET
all regions
We'll create this endpoint the same way we did for the Cities table, but instead of selecting the Cities table when adding the API endpoint, we'll select the Regions table. We'll leave the endpoint detail screen as is.
GET
single city
For this request, we want to return a single row in the Cities table, corresponding to a single city. We'll specify what city to return with a URL parameter, that will be bound to the ID field in the Cities table.
In order to create this request, we'll proceed as usual by clicking on "Add API endpoint
", then select the Cities table, and select the GET SINGLE
request type, as shown below.
We'll also leave the endpoint detail screen as is.
GET
single region
Finally, we'll create a request to get the information of a single row in the Regions table. We'll create this endpoint similarly to the previous one, but we'll select the Regions table this time.
Once we do this, we'll need to modify some information on the endpoint detail screen. Each time this single region endpoint is requested, we want to return all the information related to the cities associated with that single region as well.
To do this, we'll need to create an addon, which is a resource Xano has to extend the API response and include more data. In order to create an addon, follow these steps:
On the
Function Stack
area, click on the first row:Get Record from Regions
.On the right pane, click on
Output
. This will display how the response from the endpoint looks like. An addon allows us to include more data in the JSON response body. This data will be fetched from another table, in this case theCities
table. We'll see how the+ Addon
button is available next tocities_id
, which is a reference field for theCities
table. The addon allows to return more data from the rows in theCities
table that are referenced by thecities_id
.Click on
+ Addon
next tocities_id
. The Addon area will be displayed. Click on "Create a new addon
".In Step 1, select the
Cities
table, which is where we want to fetch the data that will be inserted in the addon.In Step 2, select
Single Item
.Leave Step 3 as is, and click
Next
. Finally, put the namecity_list
to the addon.
Now the addon is created, and the data is included in the JSON body response. Here, all the fields from the Cities
table have been included, but it's possible to select just some of them (for instance only the city name and the population).
The addon creation is shown below.
Once we create the addon, we cant test our endpoint and we'll see how the API returns the data for a single region, depending on the ID number we specify in the request URL, and its associated city data. We'll use this in one of our screens later.
🏗 Setting up the data binding on Bravo
Now, it's time to import our design into Bravo! To do this, login to Bravo and click on "New Project", then paste the link to the design file we provided (Figma). We'll see how Bravo generates the five screens we have on the design file.
Creating the requests on the Data Library
In Bravo go to Data and select Create new collection. Choose Xano Wizard. Follow the steps for entering your Api Key.
You can create different requests in the Data Library using Xano's endpoints as well. Whether you want to do it manually or use individual endpoints.
Get All Cities
We will change the name of the request given from Xano to All Cities and then we'll click on Send
.
Now, go to "Output Varibles" and make sure the following parameters are selected.
Important step: make sure the parameter corresponding to the ID of the Cities table is named as city_id
. We'll use this later for the other requests.
Get All Regions
We will change the name of the request given from Xano to All Regions.
Now, we'll create the request targeting the list of regions. Here, we won't need to obtain the individual city data yet, but only the list of all regions with their corresponding image. Click Send
, and make sure the data below is selected.
As we did for the previous request, we'll set a specific name for the data containing the id for the data records. In this case, we'll name it region_id
.
Get City Details
We will change the name of the request given from Xano to City Details.
You can see how we attach the variable city_id
to the request. This is the variable we set before, in the Get All Cities request, as the value containing the ID of a particular city. We need to make sure that they're spelled the same way in both places, otherwise, our binding won't work.
In Parameters, enter the parameter city_id
into the Key field. In the value field, enter a valid id from your database. This way, the request can return data.
Make sure the following data is selected.
Get Region Details
We will change the name of the request given from Xano to Region Details.
Finally, we'll create the request targeting the endpoint for the region details. Remember that this endpoint will also return the list of cities that belong to a specific region, depending on the region ID parameter we send in our request.
Now, make sure the following data is selected. You'll see how we select the city_id
here as well, as we'll be using the Get City Details request to get the data of the cities that belong to each region.
We changed the name of .data.cities_id[]
to City List to help us identify it in the data binding step.
Now that we have created the four requests, let's bind them to the screens for our app! 🚀
Bind the data to the screens
Now, we'll bind these four requests to the different screens in our app. Below, we show how the data binding must be done for each screen.
In Home screen will only have two buttons that navigate to other screens, so we don't need to bind any data here.
Remember that in "Regions Cities" screen, you will have to bind the container that contains the name of the city and the picture of the city to the City List.
Happy Bravorizing! 🥳
Last updated