Open phyleria opened 1 year ago
const express = require('express'); const axios = require('axios'); const app = express(); const PORT = process.env.PORT || 3000;
// Middleware for JSON parsing app.use(express.json());
// Example API Key for Chimoney (replace with your actual API key) const chimoneyApiKey = 'YOUR_CHIMONEY_API_KEY';
// Endpoint to get exchange rates from Chimoney
app.get('/getExchangeRates', async (req, res) => {
try {
// Make a request to Chimoney's 'Get List of Exchange Rates' endpoint
const response = await axios.get('https://api.chimoney.io/exchange-rates', {
headers: {
Authorization: Bearer ${chimoneyApiKey}
,
},
});
// Return the exchange rates to the frontend
res.json(response.data);
} catch (error) { console.error(error); res.status(500).json({ error: 'Error fetching exchange rates' }); } });
// Endpoint to convert local currency amount to USD app.post('/convertToUSD', async (req, res) => { try { const { localAmount, localCurrency } = req.body;
// Make a request to Chimoney's 'Convert Local Currency Amount to USD' endpoint
const response = await axios.post(
'https://api.chimoney.io/convert-to-usd',
{ localAmount, localCurrency },
{
headers: {
Authorization: `Bearer ${chimoneyApiKey}`,
},
}
);
// Return the converted amount to the frontend
res.json(response.data);
} catch (error) { console.error(error); res.status(500).json({ error: 'Error converting to USD' }); } });
app.listen(PORT, () => {
console.log(Server is running on port ${PORT}
);
});
this code may solve this issue
@phyleria I would like to contribute on this issue. could you please assign me this issue.
Example: Travelers looking to book flights and accommodations would want to compare prices in USD while making bookings in their local currency. They need a travel booking aggregator that offers this feature.
Idea Flow: