DEV Community

Cover image for How I Built a Currency Calculator API: A Step-by-Step Guide
Pratham Dabhane
Pratham Dabhane

Posted on

1

How I Built a Currency Calculator API: A Step-by-Step Guide

Introduction

Have you ever booked a cab, checked live cricket scores, or converted currency in an app? What if I told you that behind the scenes, a silent messenger called an API (Application Programming Interface) is making all of this possible?
APIs act as digital messengers that allow different applications to talk to each other. Whether you're ordering food, tracking flights, or even getting real-time currency conversion rates, APIs power it all. In this blog, I’ll break down APIs and walk you through a Currency Converter API that I built from scratch!

Types of APIs

There are various types of APIs, but prominent ones are REST APIs, SOAP and GraphQL:

  • REST API: The most popular API type—simple, fast, and supports multiple data formats like JSON and XML. Ideal for web apps and cloud-based services.
  • SOAP API: More structured, XML-based, and packed with built-in security. Often used in enterprise applications like banking systems.
  • GraphQL: Think of it as an "API on demand" that fetches exactly the data you need—no more, no less. Perfect for modern apps needing efficient data retrieval.

Why REST APIs are widely used?

REST APIs are stateless, meaning each request carries all the necessary information without relying on previous requests. This makes them highly scalable, flexible, and easy to implement, which is why they dominate modern web developme

My Story of The Currency Calculator API

One day, while looking at fluctuating exchange rates, I thought—"What if I built an API that instantly converts currency with real-time data?" That’s how I created Currency Calculator API using Python and Flask!
The API takes in three simple parameters:

  • from_currency(e.g., USD)
  • to_currency(e.g., INR)
  • amount(e.g., 100)

And it returns the converted amount in real-time JSON format.

Tech Stack & Deployment

I built this API using Python and Flask, utilizing Flask routes to handle requests. To fetch real-time currency rates, I integrated a third-party service called ExchangeRate-API.

For deployment, I used Render—a cloud hosting platform perfect for deploying web applications effortlessly.

Currently This API just takes the two currencies to convert in and an amount which is then returned to the user

The following is the example of the API

📌Example API Request:

https://currency-calculator-r7zg.onrender.com/convert?from=USD&to=INR&amount=100


Enter fullscreen mode Exit fullscreen mode

📌Example JSON Response:

{
  "amount": "100.0 USD",
  "converted_amount": "8699.6 INR",
  "from": "USD",
  "to": "INR"
}
Enter fullscreen mode Exit fullscreen mode

✅ What happens here?

  • The API fetches real-time exchange rates.
  • Converts 100 USD to INR based on the latest market rate.
  • Returns a structured JSON response.

🚀 Want to try it yourself?

You can test the API with your own currency values here:
👉 Live API Demo

The project is open-source, and you can contribute or modify it! Check out the full code on GitHub:
🔗 GitHub Repository: Currency-Calculator

Your Thoughts?

Have you ever faced API-related challenges? Drop your thoughts and feedback in the comments! 🚀

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay