databasetab in Xano (on the left), we'll click
Add Table, and name it Cities. Two fields are already created in the table:
created_at. We'll add the following fields (by clicking the
Uploadbutton in the "picture" field. You can upload any picture you wish, we used Unsplash to search for license-free images from each city.
Table Referencetype. In "Choose Database Model", we'll select the Cities table. Now a field called
cities_idhas 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
liststructure, instead of "single".
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.
Add API endpointon the top right. Select
CRUD Database Operations,
Citiestable, 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".
Run & Debugon the top right, and we'll see how we get all the data from the Cities table returned.
Add API endpoint", then select the Cities table, and select the
GET SINGLErequest type, as shown below.
Function Stackarea, click on the first row:
Get Record from Regions.
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
Citiestable. We'll see how the
+ Addonbutton is available next to
cities_id, which is a reference field for the
Citiestable. The addon allows to return more data from the rows in the
Citiestable that are referenced by the
+ Addonnext to
cities_id. The Addon area will be displayed. Click on "
Create a new addon".
Citiestable, which is where we want to fetch the data that will be inserted in the addon.
Next. Finally, put the name
city_listto the addon.
Citiestable have been included, but it's possible to select just some of them (for instance only the city name and the population).
**GET**requests, one per Xano endpoint.
**Send**", and make sure the data below is selected.
XANO_URLwith the URL for the endpoint):
city_idto 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.
city_idinto the Key field. In the value field, enter a valid id from your database. This way, the request can return data.
regions_idvariable we specified in the "Get All Regions" request.
city_idhere as well, as we'll be using the Get City Details request to get the data of the cities that belong to each region.
.data.cities_idto City List to help us identify it in the data binding step.