Git Product home page Git Product logo

convertcurrency's Introduction

Convert Currency API

API Rest that is able to perform a conversion between two currencies using updated rates from an external service Exchange Rates API. To carry out the convention, it is necessary to register a user who wants to perform the conversion.

Exchange Rates API

With over 15 exchange rate data sources, the Exchangerates API is delivering exchanging rates data for more than 170 world currencies.

In this project is used Latest Rates Endpoint.

Latest Rates Endpoint

This endpoint, depending on your subscription plan will return real-time exchange rate data which gets updated every 60 minutes, every 10 minutes, or every 60 seconds.

The Exchange Rates API free plan is limited to 1000 requests per month and has access only to conversions based on the EUR currency, so the project has the intelligence to recover the conversion for both currencies and find the rate that should be applied in the conversion.


How to run?

There are a few ways to use the application:

In Heroku

The application is available at Hekuro

In Docker

Has an image hosted on the Docker Hub: https://hub.docker.com/repository/docker/raytottifa/convert-currency

docker pull raytottifa/convert-currency:latest
docker run -p 8080:8080 
    -e API_EXCHANGE_ACCESS_KEY='51feb7685b0f35b307191ac711b3784a' 
    -e API_EXCHANGE_URI='latest?base=EUR&access_key={key}&symbols={to},{from}' 
    -e API_EXCHANGE_URL='http://api.exchangeratesapi.io/' 
    -e DATASOURCE_URL='jdbc:h2:mem:convert' 
    -e DATASOURCE_USER=sa 
    -e DATASOURCE_PASSWORD=admin 
    -e PORT=8080 
    convert-currency

In IDE

Getting started

To run the project, you will need to install the following programs:

Development

To start development, you need to clone the GitHub project in a directory of your choice:

git clone https://github.com/raytotti/convertcurrency.git

In the IDE settings Run/Debug it is necessary to inform the main class Application and the VM Options below:

-DAPI_EXCHANGE_ACCESS_KEY=51feb7685b0f35b307191ac711b3784a
-DAPI_EXCHANGE_URL=http://api.exchangeratesapi.io/
-DAPI_EXCHANGE_URI=latest?base=EUR&access_key={key}&symbols={to},{from}
-DDATASOURCE_URL=jdbc:h2:mem:convert
-DDATASOURCE_USER=sa
-DDATASOURCE_PASSWORD=admin
-DPORT=8080

Build

To build the project with Maven, run the commands below:

mvn clean install

The command will download all project dependencies and create a target directory with the built artifacts, which include the project's jar file. In addition, tests will be run, and if any fail, Maven will display this information on the console.


How to use?

One of the options is to use the Swagger that is configured in the application at path /swagger-ui.html.

Swagger

And you will have access to the endpoints Users and Transactions.

Users

Users

To create a user you need to send the post request.

User-post

Request example:

{
  "cpf": "722.629.620-90",
  "name": "João da Silva"
}

Response body example:

{
  "id": "4faaad29-494e-422d-8aa6-86d9f2762dc8",
  "cpf": "722.629.620-90",
  "name": "João da Silva"
}

Response headers example:

location: http://localhost:8080/api/v1/users/4faaad29-494e-422d-8aa6-86d9f2762dc8 

Transaction

Transactions

To create a transaction you need to send the post request.

User-post

Request example:

{
  "destinationCurrency": "BRL",
  "originCurrency": "USD",
  "originValue": 10,
  "userId": "4faaad29-494e-422d-8aa6-86d9f2762dc8 "
}

Response body example:

{
  "id": "bf94085f-b266-45d8-bfb1-82f22501937d",
  "userId": "4faaad29-494e-422d-8aa6-86d9f2762dc8",
  "originCurrency": "USD",
  "originValue": 10,
  "destinationCurrency": "BRL",
  "destinationValue": 54.77056,
  "conversionRate": 5.477056,
  "createdAt": "2021-10-06T03:06:00.273882Z"
}

Response headers example:

location: http://localhost:8080/api/v1/transactions/bf94085f-b266-45d8-bfb1-82f22501937d

Monitoring

This application is configured with Spring Boot Actuator by accessing the path /actuator you will have access to the monitoring endpoints. As in the example below.

{
    "_links": {
        "self": {
            "href": "http://localhost:8080/actuator",
            "templated": false
        },
        "beans": {
            "href": "http://localhost:8080/actuator/beans",
            "templated": false
        },
        "caches": {
            "href": "http://localhost:8080/actuator/caches",
            "templated": false
        },
        "caches-cache": {
            "href": "http://localhost:8080/actuator/caches/{cache}",
            "templated": true
        },
        "health": {
            "href": "http://localhost:8080/actuator/health",
            "templated": false
        },
        "health-path": {
            "href": "http://localhost:8080/actuator/health/{*path}",
            "templated": true
        },
        "info": {
            "href": "http://localhost:8080/actuator/info",
            "templated": false
        },
        "conditions": {
            "href": "http://localhost:8080/actuator/conditions",
            "templated": false
        },
        "configprops": {
            "href": "http://localhost:8080/actuator/configprops",
            "templated": false
        },
        "configprops-prefix": {
            "href": "http://localhost:8080/actuator/configprops/{prefix}",
            "templated": true
        },
        "env": {
            "href": "http://localhost:8080/actuator/env",
            "templated": false
        },
        "env-toMatch": {
            "href": "http://localhost:8080/actuator/env/{toMatch}",
            "templated": true
        },
        "flyway": {
            "href": "http://localhost:8080/actuator/flyway",
            "templated": false
        },
        "loggers": {
            "href": "http://localhost:8080/actuator/loggers",
            "templated": false
        },
        "loggers-name": {
            "href": "http://localhost:8080/actuator/loggers/{name}",
            "templated": true
        },
        "heapdump": {
            "href": "http://localhost:8080/actuator/heapdump",
            "templated": false
        },
        "threaddump": {
            "href": "http://localhost:8080/actuator/threaddump",
            "templated": false
        },
        "metrics-requiredMetricName": {
            "href": "http://localhost:8080/actuator/metrics/{requiredMetricName}",
            "templated": true
        },
        "metrics": {
            "href": "http://localhost:8080/actuator/metrics",
            "templated": false
        },
        "scheduledtasks": {
            "href": "http://localhost:8080/actuator/scheduledtasks",
            "templated": false
        },
        "mappings": {
            "href": "http://localhost:8080/actuator/mappings",
            "templated": false
        }
    }
}

convertcurrency's People

Contributors

raytotti avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.