The Currency Exchange API is a RESTful service that allows users to convert between different currencies using real-time exchange rates. The API also stores conversion history in a MongoDB database.
- Convert currency using real-time exchange rates.
- Store and retrieve past conversion transactions.
- Secure environment configuration with
.env. - CORS-enabled for cross-origin requests.
- Node.js - Backend runtime environment.
- Express.js - Web framework for Node.js.
- MongoDB - NoSQL database to store conversion history.
- Mongoose - ODM library for MongoDB.
- Axios - HTTP client for fetching exchange rates.
- dotenv - Environment variable management.
- nodemon - Development tool for auto-restarting server.
- CORS - Middleware for handling cross-origin requests.
Make sure you have the following installed:
- Node.js (Latest version) - Download
- MongoDB Atlas or Local MongoDB - MongoDB Atlas
- Postman (For API testing) - Download
git clone https://github.com/BLOCK-PROGRAMR/ExchangeApi.git
cd currency-exchange-apinpm installCreate a .env file in the root directory and add the following:
PORT
MONGODB_URI
For development:
npm run dev # Uses nodemonFor production:
npm startPOST /convert
{
"from": "USD",
"to": "EUR",
"amount": 100
}{
"from": "USD",
"to": "EUR",
"amount": 100,
"convertedAmount": 92.5,
"rate": 0.925
}GET /history
[
{
"from": "USD",
"to": "EUR",
"amount": 100,
"convertedAmount": 92.5,
"rate": 0.925,
"timestamp": "2024-02-19T10:00:00.000Z"
}
]Use Postman or cURL to send requests:
Convert Currency Request (Using cURL):
curl -X POST http://localhost:5000/convert \
-H "Content-Type: application/json" \
-d '{"from":"USD", "to":"EUR", "amount":100}'Get History Request:
curl -X GET http://localhost:5000/history- Add user authentication for secured access.
- Implement caching for faster response times.
- Introduce WebSocket support for live exchange rate updates.
This project is licensed under the MIT License .