Home

3 min read

Get the Latest Exchange Rates Easily with Our API

As the global economy continues to become more interconnected, staying updated with accurate and timely exchange rates is essential for businesses, developers, and finance enthusiasts alike. This blog post introduces you to an effortless way to access exchange rates against the USD through our robust API endpoint.

Introducing the Exchange Rates Endpoint

Our exchange-rates API endpoint provides real-time exchange rates for over 150 currencies that are compatible with Stripe. By querying this endpoint, you can easily integrate it into your financial applications, e-commerce platforms, or any service that requires currency conversion.

Endpoint URL

You can fetch the exchange rates using the following client endpoint:

GET https://api.spider.cloud/data/exchange-rates?filter=usd,eur,gbp

This endpoint allows you to get exchange rates based on the USD price point, filtered by the specified currencies at 1 credit per call.

Example Request

Here’s an example request where we are asking for exchange rates for USD, EUR, and GBP:

GET https://api.spider.cloud/data/exchange-rates?filter=usd,eur,gbp

Example Response

The response from the endpoint will be a JSON object containing the exchange rates for the specified currencies. For instance:

{
  "content": {
    "usd": 1.0,
    "eur": 0.85,
    "gbp": 0.75
  }
}

Here, the exchange rates for EUR and GBP are provided relative to USD (which always has a value of 1.0).

How to Use the API

To show you how simple it is to get the exchange rates, let’s use a sample client-side example using JavaScript to fetch data from our endpoint.

Step 1: Make a GET Request

Use JavaScript to send a GET request to the https://api.spider.cloud/data/exchange-rates endpoint.

async function getExchangeRates() {
  try {
    const response = await fetch('https://api.spider.cloud/data/exchange-rates?filter=usd,eur,gbp', { headers: { authorization: process.env.SPIDER_API_KEY } });
    const data = await response.json();
    console.log("Exchange Rates:", data.content);
  } catch (error) {
    console.error('Error fetching exchange rates:', error);
  }
}

// Execute the function
getExchangeRates();

Step 2: Display the Rates

You can then use the fetched data to display the rates on your web page or perform any other operation required.

<!DOCTYPE html>
<html>
<head>
  <title>Exchange Rates</title>
</head>
<body>
  <h1>Exchange Rates</h1>
  <div id="exchange-rates"></div>

  <script>
    async function getExchangeRates() {
      try {
        const response = await fetch('https://api.spider.cloud/data/exchange-rates?filter=usd,eur,gbp', { headers: { authorization: process.env.SPIDER_API_KEY }} );
        const data = await response.json();
        document.getElementById('exchange-rates').innerText = JSON.stringify(data.content, null, 2);
      } catch (error) {
        console.error('Error fetching exchange rates:', error);
      }
    }

    // Execute the function
    getExchangeRates();
  </script>
</body>
</html>

By following these simple steps, your web page will display the current exchange rates for the specified currencies.

Conclusion

Accessing accurate and up-to-date exchange rates has never been easier. With our https://api.spider.cloud/data/exchange-rates endpoint, you can integrate currency conversion into your applications seamlessly. Whether you require exchange rates for e-commerce, financial analysis, or international business, this API endpoint is a powerful tool to meet your needs.

Happy coding! If you have any questions or feedback, feel free to leave a comment below.


Follow us on social media:

Stay tuned for more updates and guides!

Build now, scale to millions