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"}