Need to convert currencies in your application? This guide covers everything you need to know about currency conversion via API, including exchange rates, supported currencies, and implementation examples in multiple languages.
What is Currency Conversion?
Currency conversion is the process of exchanging one currency for another based on the current exchange rate. Exchange rates fluctuate constantly based on market conditions, making real-time conversion APIs essential for accurate pricing.
Currency conversion is crucial for international e-commerce, travel apps, financial services, and any application serving a global audience.
Understanding Exchange Rates
Exchange rates can be expressed in two ways:
Direct Quote
How much domestic currency is needed to buy one unit of foreign currency. Example: 1 EUR = 1.10 USD.
Indirect Quote
How much foreign currency can be bought with one unit of domestic currency. Example: 1 USD = 0.91 EUR.
Using the Currency Converter API
TinyFn provides a comprehensive endpoint for currency conversion:
GET https://api.tinyfn.io/v1/convert/currency
Headers: X-API-Key: your-api-key
{
"from": "USD",
"to": "EUR",
"amount": 100,
"rate": 0.92,
"result": 92,
"timestamp": "2024-01-15T12:00:00Z"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
from |
string | Source currency code (e.g., "USD") |
to |
string | Target currency code (e.g., "EUR") |
amount |
number | Amount to convert |
Supported Currencies
The API supports 150+ currencies including USD, EUR, GBP, JPY, CNY, INR, AUD, CAD, CHF, and many more.
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/convert/currency?from=USD&to=EUR&amount=100',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.result); // 92
console.log(data.rate); // 0.92
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/convert/currency',
params={'from': 'USD', 'to': 'EUR', 'amount': 100},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['result']) # 92
cURL
curl "https://api.tinyfn.io/v1/convert/currency?from=USD&to=EUR&amount=100" \
-H "X-API-Key: your-api-key"
Common Use Cases
- E-commerce: Display prices in customer's local currency
- Travel Apps: Convert expenses between currencies
- Financial Dashboards: Show portfolio values in different currencies
- Invoicing: Generate invoices in multiple currencies
- Price Comparison: Compare prices across international markets
Best Practices
- Cache rates: Cache exchange rates for short periods to reduce API calls
- Show timestamps: Display when rates were last updated
- Handle rounding: Use appropriate decimal places for each currency
- Validate codes: Verify currency codes before making requests
Try the Currency Converter API
Get your free API key and start converting currencies in seconds.
Get Free API Key