Currency conversion Application/API - Exchange rates are based on current foreign exchange rates published by the European Central Bank.
The main objective of this application is to provide a way to make currency conversions quickly, simply and based on a secure source.
- Elixir 1.10
- Tesla - HTTP requests client.
- Poison - JSON parser.
- Cowboy - Small Erlang/OTP HTTP server.
- ExchangeRateApi - API for exchange rates.
- ExDoc - Produces HTML and EPUB documentation.
You can follow the installation guide according to your operating system.
git clone git@github.com:maikkkko1/elixir-currency-converter.git
From the terminal in the project's root folder, run the command:
mix deps.get
If the installation has been successfully completed, the project is ready to be used!
About the IEX: https://hexdocs.pm/iex/IEx.html
From the terminal in the project's root folder, run the command to enter in the IEX mode:
iex -S mix
handle_conversion/3 - from, to, amount
Converting an amount of 1 BRL to USD, we will have in the current values the following result:
iex(1)> Conversion.handle_conversion("brl", "usd", 1)
{:ok, %{amount_converted: 0.19, amount_to_convert: 1, from: "brl", to: "usd"}}
To use it via API, it is first necessary to start the HTTP server.
From the terminal in the project's root folder, run the command to start the server:
mix run --no-halt
Now using a client for HTTP requests like Postman or Insomnia, it is possible to make the requests to perform the conversion.
Request params:
- from - required
- to - required
- amount - required
Success request
GET http://localhost:4000/api/conversion?from=brl&to=usd&amount=1
RESPONSE
{
"result": {
"to": "usd",
"from": "brl",
"amount_to_convert": "1",
"amount_converted": 0.19
},
"error": null
}
Error request
GET http://localhost:4000/api/conversion?from=brl&to=usd
RESPONSE
{
"result": null,
"error": "Amount is required"
}
From the terminal in the project's root folder, run the command to generate modules and functions documentation:
mix docs
The docs folder will be created at the root of the project where all the HTML files with the documentation will be located.
The project contains some unit tests.
From the terminal in the project's root folder, run the command to run all the unit tests:
mix test