Giter Site home page Giter Site logo

paidy-forex's Introduction

Paidy Forex

Prerequisites

  • JDK (verified with JDK 17)
  • Apache Maven

Build and test the application

To build and run unit tests, run the following command in the root folder

mvn verify

To run the application, run the following commands

docker compose up -d  # This runs the paidyinc/one-frame container
./run.sh  # This runs application on port 80. To use a different port, config.properties needs to be modified.

To get an exchange rate, run the following command (or open the url with a web browser)

curl "http://127.0.0.1/rate?from=USD&to=JPY"

An example of the output looks like

{"rate":0.71,"from":"USD","to":"JPY"}

API Specification

The following is the more formal API specification.

Parameter Type Required Description
from string yes Source currency code. Supported currency codes are AUD, CAD, CHF, EUR, GBP, NZD, JPY, SGD, USD.
to string yes Target currency code. Supported currency codes are AUD, CAD, CHF, EUR, GBP, NZD, JPY, SGD, USD.

Successful Response

  • Response headers
    • Content-Type: application/json
  • Response body
Parameter Type Description
from string Source currency code.
to string Target currency code.
rate number Exchange rate of the given currency pair.

Example of response

HTTP/1.1 200 OK
Date: Fri, 01 Apr 2022 13:33:20 GMT
Content-type: application/json
Content-length: 38

{"rate":0.29,"from":"USD","to":"JPY"}

Error Response

When either or both of from or to parameters are missing, the application returns 400 response. Here is an example response when to parameter is missing.

HTTP/1.1 400 Bad Request
Date: Fri, 01 Apr 2022 13:39:26 GMT
Content-type: application/json
Content-length: 73

{"message":"Parameters are invalid","errors":{"to":"Required parameter"}}

The following is a response example when an unsupported currency code is queried.

HTTP/1.1 400 Bad Request
Date: Fri, 01 Apr 2022 15:57:09 GMT
Content-type: application/json
Content-length: 80

{"message":"Parameters are invalid","errors":{"to":"Unsupported currency code"}}

The following is a response example when an exchange rate for a same currency is queried.

HTTP/1.1 400 Bad Request
Date: Fri, 01 Apr 2022 15:57:09 GMT
Content-type: application/json
Content-length: 95

{"message":"Parameters are invalid","errors":{"to":"Different currencies should be specified"}}

When one-frame API is unavailable (when the container is not running or reached the rate limit), the application returns 503 response. Here is the response example.

HTTP/1.1 503 Service Unavailable
Date: Fri, 01 Apr 2022 13:45:32 GMT
Content-type: application/json
Content-length: 48

{"message":"Service is temporarily unavailable"}

paidy-forex's People

Contributors

shu-yusa avatar

Watchers

James Cloos avatar  avatar

paidy-forex's Issues

Reusable data caching

To make the caching reusable to different use cases in the future, the following refactoring can be considered.

  • Define a generic interface QueryService
  • Extract caching logic as a decorator

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.