Share My Creation SithasoDaisy Countries REST API Explorer (Source Code)

Hi there

The attached source code lets you explore the countries API..

We use BANanoFetch to fetch and display countries related data from


SDCountAPI.jpg
 

Attachments

  • SithasoCountriesAPI.zip
    45.1 KB · Views: 123
Last edited:

Mashiane

Expert
Licensed User
Longtime User
How to?

  • Open B4J
  • Click File > New > SithasoDaisyPocketBase
  • Main > AppName = sdcountries
  • Main > AppTitle = SithasoDaisy Countries REST API Explorer
  • Copy BlankLayout to pgCountries & update with code from example.
  • Copy tablelayout to countrieslayout and rename the tbltable to tblcountries
  • countrieslayout > SDUIPage > Page Name* = countries
  • countrieslayout > SDUIRow1 > ParentID = countries
  • Leave only these ones and generate members on pgCountries for countrieslayout

1686118489569.png


1686118234159.png



The code that fetches the data and displays it is:

B4X:
Sub mounted
    app.PagePause
    'Show loading indicator
    tblcountries.RefreshLoading = True
    Dim j As SDUIFetch
    j.Initialize("https://restcountries.com/v2/all")
    banano.Await(j.GetWait)
    Dim countriesL As List
    countriesL.Initialize
    
    If j.Success Then
        Dim Response As List = j.ToList
        For Each c As Map In Response
            Dim nm As Map = SDUIShared.MapCopyKeys(c, Array("area","capital","flag","name","population","languages","latlng","callingCodes"))
            Dim scallingcode As String = SDUIShared.MapJoinKey(nm, "callingCodes", ",")
            Dim slanguages As String = SDUIShared.MapJoinKey(nm, "languages.name", ",")
            nm.Put("callingcode", scallingcode)
            nm.Put("languages", slanguages)
            countriesL.Add(nm)
        Next
    End If
    banano.Await(tblcountries.SetItemsPaginate(countriesL))
    'sum the totals of each of these columns
    Dim summary As Map = tblcountries.SetFooterTotalSumCountColumns(Array("population"))
    spopulation = summary.Get("population")
    'get the total number of processed rows
    srowcount = summary.Get("rowcount")
    'format the value to be a thousand
    srowcount = SDUIShared.Thousands(srowcount)
    'merge these columns
    tblcountries.SetFooterColumnsMerge(Array("name","flag"))
    'set the first column to show the total
    tblcountries.SetFooterColumn("name", $"Total (${srowcount})"$)
    'Hide loading indicator
    tblcountries.RefreshLoading = False
    app.PageResume
End Sub


Happy Coding...
 
Last edited:
Top