Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gvolpe/exchange-rates
:currency_exchange: Querying a rate-limited currency exchange API using Redis as a cache
https://github.com/gvolpe/exchange-rates
cache dhall dhall-lang exchange-rates forex haskell rate-limiter redis transient wreq
Last synced: 3 months ago
JSON representation
:currency_exchange: Querying a rate-limited currency exchange API using Redis as a cache
- Host: GitHub
- URL: https://github.com/gvolpe/exchange-rates
- Owner: gvolpe
- License: apache-2.0
- Created: 2019-06-09T22:00:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-07T02:49:06.000Z (almost 5 years ago)
- Last Synced: 2024-10-11T23:45:41.845Z (3 months ago)
- Topics: cache, dhall, dhall-lang, exchange-rates, forex, haskell, rate-limiter, redis, transient, wreq
- Language: Haskell
- Homepage:
- Size: 187 KB
- Stars: 41
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ![icon](icon.png) exchange-rates
[![CircleCI](https://circleci.com/gh/gvolpe/exchange-rates.svg?style=svg)](https://circleci.com/gh/gvolpe/exchange-rates)
Querying a [rate-limited foreign currency exchange API](https://free.currencyconverterapi.com/) using [Redis](https://redis.io/) as a cache.
- Number of Requests per Hour: 100 (See config file)
### Http Endpoints
#### GET /v1/currencies
Returns a list of the available currencies. Eg:
```json
["USD","EUR","GBP","AUD","CAD","PLN","ARS"]
```#### GET /v1/rates?from=EUR&to=USD
Returns the current exchange rate, if available:
```json
{"to":"USD","from":"EUR","rate":1.139556}
```### Run it locally
You'll need a Redis instance. The easiest way to get started is by using `docker`:
```
docker run -it --rm -p 6379:6379 redis:5.0.0
```And then run the web server app using `cabal new-run exchange-rates`, or using Nix `nix-shell --pure shell.nix` and `cabal 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.
### Browse the documentation
The docs are generated at compile time from the API definition. The API serves a `swagger.json` response that you can visualize in the Swagger UI:
```
docker run -p 80:8080 swaggerapi/swagger-ui
```Go to `localhost` and enter `http://localhost:8080/swagger.json`.
![docs](docs.png)