I am trying to simulate a REST api endpoint function where I want to check the endpoint for an exchange currency
Trying on postman
and i Do this
https://api.flutterwave.com/v3/transfers/rates?amount=1000&destination_currency=USD&source_currency=KES
thereafter i input my secret key I get this as response
{
"status": "success",
"message": "Transfer amount fetched",
"data": {
"rate": 140.556,
"source": {
"currency": "KES",
"amount": 140556
},
"destination": {
"currency": "USD",
"amount": 1000
}
}
}
Now i want to make this into a function, And i want to get the equivalient currency as shown above
See the function I am trying to simulate
const GetEqCurrency = async (source_currency, destination_currency, amount) => {
var header = {
Accept: "application/json",
"Content-type": "application/json",
Authorization:
"Bearer FLWSECK_TEST-153740d351951b5f6d5ae8b903e0c467-X",
};
var url = `https://api.flutterwave.com/v3/transfers/rates?amount=${amount}&destination_currency=${destination_currency}&source_currency=${source_currency}`;
fetch(url,
{ method: "GET", headers: header }).then((response) => response.json())
.then((responseJson) =>{
if(responseJson.message == 'Transfer amount fetched'){
//console.log()
// Help me output the equivalient data here in json
}
})
};
How do I output the following value in json Please help me here.
2
Answers
You need to
return
what you need from the function:FYI – You can use Postman to generate sample snippets of your fetch request. Have a look here
Then try this: