2. Visualize Data from API
How to easily display data from REST API backend?
Last updated
How to easily display data from REST API backend?
Last updated
Prepare a basic Customer Search application connecting data using REST API Integration.
Typical usage of the REST API Integration can be loading data from a JSON server, in our case, Mock API. We will connect to customer data which content would be a part of the Advanced Table filtered by a dynamic search field. Additionally, each Table record has its icon triggering the e-mail client.
How to use the REST API Integration.
Working with an Advanced Table.
Triggering an E-mail client.
As usual, let's start with a Layout preparation. The Main Container will contain a Header, Search Field, and Advanced Table.
Place in MainView
a Container, name its ID -> cntRoot
, and configure it as follows:
Flow -> Under each Other
; Horizontal Alignment -> Stretch
; Padding -> X-Wide
; Spacing -> Medium
;
As a Header, we will simply use a Label with the ID -> heading
.
Set up heading
properties: Value -> "Customers
"; Font Size -> XLARGE
;
Icon -> Name -> "mdi/briefcase-account
"; Size -> Large
; Flow -> Icon left
Style -> Horizontal Alignment -> Left
; Vertical Alignment -> Middle
Put in a Text Input component, serving as Search Field. Name its ID -> fldSearch
, and it's Placeholder -> "Search...
"
The last component will be an Advanced Table carrying ID -> tblCustomers
; Spacing -> Medium
;
Add five Columns and simply name them as follows: First Name
; Last Name
; Email
; Company
; #5
Set up Column #5
Width -> 36px
Place to each of the Columns the following components:
Text -> ID -> txtFirstName
Text -> ID -> txtLastName
Text -> ID -> txtEmail
Text -> ID -> txtCompany
Button -> ID -> btnSendEmail
; Value -> ""; Icon -> Name -> "mdi/email-edit
"; Size -> Medium
Style -> Button Style -> Custom; Background -> Transparent
; Foreground -> Secondary
; Border Color -> LIGHT_GRAY
; Border Width -> 1px
Custom hover state -> Background -> Transparent
; Foreground -> PRIMARY
; Border Color -> PRIMARY
Don't hesitate to use our JSON Server or use your own. The Base URL of the Server configuration has to exclude the customer data subdirectory, which would be targeted further by an Action.
Keep in mind that targeted data must be in a valid JSON format.
Create a new Rest API Integration, name it MyRestApi
and configure as follows:
Base URL -> "https://mockapi.adapptio.app/2c932729/rest
"
API Timeout -> 10000
Save it and continue with the next steps.
GetCustomers
ActionThe GetCustomers
Action provides a bridge between MyRestApi
Integration and Datasource bound in the MainView
, which we will configure in the upcoming step. Input search parameter equals GET Query String.
If additional Query parameters are required, it has to be solved on the side of the input parameter.
Create a Action and name it GetCustomers
.
Add a Parameter with ID -> search
; String
On Start ->Place a REST API / Request from Functions / Integrations Panel and configure it as follows:
ID -> apiReq
; Parameters URL -> "/customers
"
Add a new Query, name it q
and set up its Value as ƒx Function -> params.search
Wire together a new Output and set up its Return value -> apiReq.data
GetCustomer
Action with customers
DatasourceSomehow we have to bind our REST API data with MainView. We have to Add Data from Action in Outline Panel for such a reason.
Click on Add Data from Action and name it customers
Select by clicking on Action Name -> GetCustomers
Bind Search field Value with Input parameter by ƒx Function on search -> fldSearch.value
customers
Datasource with tblCustomers
TableAssociating customers
Datasource with our Advanced Table items is the last step in making our application live.
Watch the difference between annotation in binding items
Datasource and Values of included components, where its Value is item
.
Switch on tblCustomers
Properties and edit Items -> customers.data
(ƒx)
Associate all Columns components, except Button, with the following Functions:
txtFirstName
-> Value -> item.first_name
(ƒx)
txtLastName
-> Value -> item.last_name
(ƒx)
txtEmail
-> Value -> item.email
(ƒx)
txtCompany
-> Value -> item.company
(ƒx)
The last step in our application process is to associate an Event on Click btnSendEmail
Button.
Switch on btnSendEmail
and create a new Event by clicking on Click in Inspector Panel.
On Event -> Add a Navigate function, wire it together and set it up as follows:
Options -> Link Type -> URL
; URL Address -> mailto:${item.email}
REST API belongs with Databases in one of the most used Integrations in the Adapptio. Try to bind another free online JSON Servers.