-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.bal
21 lines (17 loc) · 946 Bytes
/
service.bal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import ballerinax/worldbank;
import ballerina/http;
service /country on new http:Listener(9090) {
# A resource for generating greetings
# + name - the input string name
# + return - string name with hello message or error
resource function get info/[string country]() returns json|error {
// Send a response back to the caller.
worldbank:Client worldbankEndpoint = check new ({});
worldbank:IndicatorInformation[] populationByCountry = check worldbankEndpoint->getPopulationByCountry(country);
float populationInMillions = <float>(populationByCountry[0]?.value ?: 0) / 1000000;
worldbank:IndicatorInformation[] gdpByCountry = check worldbankEndpoint->getGDPByCountry(country);
float countryGDP = <float>(gdpByCountry[0]?.value ?: 0);
json countryInfo = {country: country, populationInMillions: populationInMillions, GDP: countryGDP};
return countryInfo;
}
}