Giter VIP home page Giter VIP logo

exchange-service's Introduction

Foreign Exchange Rate Service

Provide a simple API to convert between foreign exchange rates.

Based on EUR exchange rates provided by European-Central-Bank.

Data Source

Exchange rates as provided by European Central Bank

Under the hood

  • On application startup, the rates are imported from ECB XML feed.
  • Uses both daily and 90-day-historic XML feeds.
  • Rates are stored in an in-memory database.
  • Rates are updated every hour.

Lets go!

NOTE: this project uses Lombok. For full IDE support you might need to install a plugin.

Running the application

mvn spring-boot:run

Use the service

curl -i -H "Accept: application/json" localhost:8080/api/status
curl -i -H "Accept: application/json" localhost:8080/api/currencies
curl -i -H "Accept: application/json" localhost:8080/api/rates/USD/2016-01-21
curl -i -H "Accept: application/json" 'localhost:8080/api/conversion/USD/CHF/1?date=2016-01-21'

Endpoints

/api/status

Response:

{"isReady":true}

isReady:false until rates have been loaded from webservice for the first time.
isReady:true after rates have been loaded once.

/api/currencies

Provides all strings available to use as currency parameter when querying /api/rates/{currency}/{date}

Response:

["AUD","BGN","BRL","CAD","CHF","CNY","CZK","DKK","GBP","HKD","HRK","HUF","IDR","ILS","INR","JPY","KRW","MXN","MYR","NOK","NZD","PHP","PLN","RON","RUB","SEK","SGD","THB","TRY","USD","ZAR"]

/api/rates/{currency}/{date}

Path-Variables:

Request & Response:

curl -H "Accept: application/json" localhost:8080/api/rates/USD/2016-01-21
{"rate":1.09}

Where '1.09' is the foreign exchange rate for EUR to USD on 2016-01-21.

Possible http-status codes:

  • 200 - requested rate found and returned
  • 404 - requested rate not found for currency & date combination (history is until 90 days back, no rates on weekends)
  • 503 - if rates have not been loaded yet. corresponds to {"isReady":false} of /api/status

/api/conversion/{fromCurrency}/{toCurrency}/{amount}?date={date}

Path-Variables / Request-Variables:

  • {fromCurrency} use any string as provided by /api/currencies
  • {toCurrency} use any string as provided by /api/currencies
  • {amount} amount
  • {date} (optional) ISO 8601 formatted date

Request & Response:

curl -H "Accept: application/json" 'localhost:8080/api/conversion/USD/CHF/1?date=2016-01-21'
1.000000000000000000000000000000000046

Possible http-status codes:

  • 200 - converted amount returned
  • 404 - requested rate not found for currency & date combination (history is until 90 days back, no rates on weekends)
  • 503 - if rates have not been loaded yet. corresponds to {"isReady":false} of /api/status

Improvement ideas

  • expose metrics/health/etc. (e.g. via spring boot actuator)
  • make scheduling bullet-proof
  • improve error handling for data-retrieval (when updating rates)
  • add interactive documentation with swagger
  • add HATEOAS

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.