Skip to content

Instantly share code, notes, and snippets.

@adrianhajdin
Created July 29, 2022 10:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save adrianhajdin/8f9f36dc3b789b2899bbcf80493b2a1e to your computer and use it in GitHub Desktop.
Save adrianhajdin/8f9f36dc3b789b2899bbcf80493b2a1e to your computer and use it in GitHub Desktop.
I Abandoned Postman for This NEW VS Code Extension | Build, Test & Sell APIs 🤑
import axios from 'axios';
const getCountries = async (currencyCode) => {
try {
const response = await axios.get(`https://restcountries.com/v3.1/currency/${currencyCode}`);
return response.data.map(country => country.name.common);
} catch (error) {
throw new Error(`Unable to get countries that use ${currencyCode}`);
}
};
const convertCurrency = async (fromCurrency, toCurrency, amount) => {
const countries = await getCountries(toCurrency);
const convertedAmount = (amount * Math.random() * 11).toFixed(2);
return `${amount} ${fromCurrency} is worth ${convertedAmount} ${toCurrency}. You can spend these in the following countries: ${countries}`;
};
convertCurrency('USD', 'CHF', 20)
.then((data) => console.log(data))
.catch((error) => console.log(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment