Querying arate-limited foreign currency exchange APIusingRedisas a cache.
- Number of Requests per Hour: 100 (See config file)
Returns a list of the available currencies. Eg:
["USD","EUR","GBP","AUD","CAD","PLN","ARS"]
Returns the current exchange rate, if available:
{"to":"USD","from":"EUR","rate":1.139556}
You'll need a Redis instance. The easiest way to get started is by usingdocker
:
docker run -it --rm -p 6379:6379 redis:5.0.0
And then run the web server app usingcabal new-run exchange-rates
,or using Nixnix-shell --pure shell.nix
andcabal new-run exchange-rates
.You should see something like:
AppConfig {forex = ForexConfig {host = "https://free.currconv.com/api/v7", apiKey = [SECRET], keyExpiration = 1800}, redis = RedisConfig {redisHost = "127.0.0.1", redisPort = 6379}}
Started server on localhost:8080
Calling web service for: USD -> GBP
Calling web service for: USD -> EUR
Cache hit: USD -> GBP
Calling web service for: USD -> PLN
Cache hit: USD -> PLN
Exchange rates are cached to avoid hitting the (limited) external service many times.
The docs are generated at compile time from the API definition. The API serves aswagger.json
response that you can visualize in the Swagger UI:
docker run -p 80:8080 swaggerapi/swagger-ui
Go tolocalhost
and enterhttp://localhost:8080/swagger.json
.