This project implements a simple currency converter in Java, using the Exchange Rate API to obtain updated exchange rates and Maven for dependency management.
- Java: Programming language used for development.
- Maven: Automation tool for building and dependency management.
- Gson: Library for converting Java objects to JSON and vice-versa.
- Exchange Rate API: Provides real-time currency exchange rate data. More information can be found at Exchange Rate API.
To run this project, you will need:
- Install Java JDK if it is not already installed. Download JDK
- Install Maven if it is not already installed. Install Maven
- Clone this repository or download the files to your local machine.
- Open the project in IntelliJ IDEA or another IDE of your choice that supports Maven.
- Run
mvn clean install
to install dependencies. - Obtain a free API key from Exchange Rate API and configure it in your project.
- Run the project using the command
mvn exec:java -Dexec.mainClass=CurrencyConverter
or through your IDE.
Your API key will be active & enabled after email confirmation.
No client library required - just use cURL or the HTTP library in your development environment. See the documentation for the currency conversion API endpoint URLs & formats.
The response you've received can be parsed by your development environment's JSON library. You're done! Use the fresh exchange rate data to convert currencies in your application with ease.
To use the Standard endpoint simply make the two substitutions explained below and then send a GET request:
- Substitute
YOUR-API-KEY
with the API key displayed in your dashboard. - Substitute
USD
with the code you want to use as a base currency.
The API uses ISO 4217 Three Letter Currency Codes - e.g. USD for US Dollars, EUR for Euro etc. Here are the codes we support.
Example GET request:
GET https://v6.exchangerate-api.com/v6/YOUR-API-KEY/latest/USD
This will return the exchange rates from your base code to all the other currencies they support:
{
"result": "success",
"documentation": "https://www.exchangerate-api.com/docs",
"terms_of_use": "https://www.exchangerate-api.com/terms",
"time_last_update_unix": 1585267200,
"time_last_update_utc": "Fri, 27 Mar 2020 00:00:00 +0000",
"time_next_update_unix": 1585353700,
"time_next_update_utc": "Sat, 28 Mar 2020 00:00:00 +0000",
"base_code": "USD",
"conversion_rates": {
"USD": 1,
"AUD": 1.4817,
"BGN": 1.7741,
"CAD": 1.3168,
"CHF": 0.9774,
"CNY": 6.9454,
"EGP": 15.7361,
"EUR": 0.9013,
"GBP": 0.7679,
"EUR": 0.9013,
"GBP": 0.7679,
"...": 7.8536,
"...": 1.3127,
"...": 7.4722,
"etc.": "etc."
}
}
{
"result": "error",
"error-type": "unknown-code"
}
Where "error-type"
can be any of the following:
"unsupported-code"
if they don't support the supplied currency code (see supported currencies)."malformed-request"
when some part of your request doesn't follow the structure shown above."invalid-key"
when your API key is not valid."inactive-account"
if your email address wasn't confirmed."quota-reached"
when your account has reached the number of requests allowed by your plan.
Contributions are welcome. To contribute:
- Fork the project.
- Create a branch for your feature (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a Pull Request.
Distributed under the MIT License. See LICENSE
for more information.
Jonnathan Ribeiro - [email protected]
Project Link: https://github.com/jonnrib/challenge-one-converter