I have an API getting exchange rates.
This is the Backend
import {fetch} from 'wix-fetch';
export function getCurrency(currency,baseCurrency) {
const url = 'https://api.fixer.io/latest?base=';
let fullUrl = url + baseCurrency + '&symbols=' + currency;
return fetch(fullUrl, {method: 'get'})
.then(response => response.json())
.then(json => json.rates[currency].toString());
}
This is my page code
import {getCurrentTemp, getCurrency} from 'backend/ArenaApi';
export function button1_click(event, $w) {
getCurrency($w("#currencysymbol").value,$w("#baseCurrency").value)
.then(rates => $w("#currencyrate").text = "1 " + "USD" + " = " + rates + " " + ($w("#currencysymbol").value));
$w("#currencyrate").show();
}
My backend is posting the URL and getting this string in return
“base”:“USD”,“date”:“2018-05-22”,“rates”:{“EUR”:0.84789}}
as you can see that my backend is retrieving the “rates” value from the string via
.then(json => json.rates[currency].toString());
which is being entered into the Page Text element via
.then(rates => $w(“#currencyrate”).text = “1 " + “USD” + " = " + rates + " " + ($w(”#currencysymbol").value));
My Question:
How can I retrieve multiple values from a string; in this case “base” “date” & “rates” altogether so that I can inject them into different text elements on a page
_/_