Xano: Build nested lists (list > list > detail page)

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_id 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_id" 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_id" 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 the Cities table. We'll see how the + Addon button is available next to cities_id, which is a reference field for the Cities table. The addon allows to return more data from the rows in the Cities table that are referenced by the cities_id.

  • Click on + Addon next to cities_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 name city_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

First, we'll create the different requests on the Data Library, in order to target the endpoints we just created on Xano. We'll create the following **GET** requests, one per Xano endpoint.

Get All Cities

In this request, we'll target the endpoint returning the list containing all the cities. Once pasted the URL of the endpoint (we need to get that from Xano), we'll click on **Send**.

https://XANO_URL/cities

If the URL is pointing correctly to the endpoint, we should see the data coming from Xano in the "Received Data" tab under the request URL. Now, go to "Selected Data" 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 (see below). We'll use this later for the other requests.

Get 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. Create the request the same way we did before, click "**Send**", and make sure the data below is selected.

https://XANO_URL/regions

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 regions_id.

Get City Details

We'll create this request to target the endpoint returning the details for a single city. We'll set the following URL (replace XANO_URL with the URL for the endpoint):

https://XANO_URL/cities/${city_id}

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

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.

We'll set the following URL, attaching this time the regions_id variable we specified in the "Get All Regions" request.

https://XANO_URL/regions/${regions_id}

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.

"Home" screen

This screen will only have two buttons that navigate to other screens, so we don't need to bind any data here.

"Cities" screen

Bind the data as follows.

"Regions" screen

Bind the data as follows.

"Region Cities" screen

Bind the data as follows.

"City Detail" screen

Bind the data as follows.

Happy Bravorizing! 🥳

Last updated