API for converting between BRL, USD, EUR, JPY currencies.
- Tools
- Consumed API
- Setup a postgres database url in
.env
fileDATABASE_URL
, exemple:
API_KEY=123456990120310912031 # Visit https://apilayer.com and put your API key here
DATABASE_URL="postgresql://<DATABASE_USER>:<DATABASE_PASS>@localhost:5432/currency_converter_db"
OBS: If you don't have Postgres in your machine but have docker compose, just run docker-compose up
to instantiate a postgres image
- Run Prisma migrations and Prisma Client setup
npm run prisma:migrate
npm run prisma:generate
- Run the project
npm run dev
Try to use the currency conversion doc
- Create transactions to convert currencies
# /api/v1/transactions
curl -X POST http://localhost:3333/api/v1/transactions \
-H 'Content-Type: application/json' \
-d '{ "from": "BRL", "to": "USD", "amount": 5 }'
- List registered transactions
# /api/v1/transactions
curl -X GET http://localhost:3333/api/v1/transactions \
-H 'Content-Type: application/json'
📦 currency-converter
┣ 📂 prisma
┣ 📂 src
┃ ┣ 📂 common-types
┃ ┣ 📂 exception
┃ ┣ 📂 providers
┃ ┃ ┃ ┣ 📂 database
┃ ┃ ┃ ┣ 📂 http-client
┃ ┣ 📂 v1
┃ ┃ ┣ 📂 entities
┃ ┃ ┣ 📂 middlewares
┃ ┃ ┣ 📂 repositories
┃ ┃ ┣ 📂 use-cases
┃ ┃ ┃ ┣ 📂 create-transaction
┃ ┃ ┃ ┣ 📂 list-transaction
┃ ┣ 📜 routes
┃ ┣ 📜 index.ts
┣ 📜 .gitignore
┣ 📜 docker-compose.yml
┣ 📜 README.md
┣ 📜 LICENSE
┣ 📜 package-lock.json
┣ 📜 package.json
┣ 📜 tsconfig.json
Thinking about a simple project, easy to test and with high capacity to improvements, the API was built using the clean architecture principles. It came up with pros and cons, like tools limitation that could work togheter respecting these principles. Prisma and axios are one of those! Prisma combined the ability to work with repositories without dirt things in our entities and low accoplament, for example. Axios, on the other hand, provided a way to handle with http client to handle with requests.
Henrique Barros