frankfurter/README.md

76 lines
1.7 KiB
Markdown
Raw Normal View History

2017-11-04 18:59:51 +01:00
# Fixer
2017-11-04 18:59:51 +01:00
[![Travis](https://travis-ci.org/hakanensari/fixer.svg)](https://travis-ci.org/hakanensari/fixer)
2015-07-28 17:27:10 +02:00
2017-11-04 18:59:51 +01:00
Fixer is a free API for current and historical foreign exchange rates [published by the European Central Bank](https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html).
2016-04-11 15:38:28 +02:00
2017-11-04 18:59:51 +01:00
A public instance of the API lives at [https://api.fixer.io](https://api.fixer.io). Alternatively, you can run privately with the provided Docker image.
2015-07-28 17:27:10 +02:00
2017-11-04 18:59:51 +01:00
Rates are updated around 4PM CET every working day.
2016-04-11 15:38:28 +02:00
## Usage
2017-11-04 18:59:51 +01:00
Get the latest foreign exchange rates.
2016-04-11 15:38:28 +02:00
```http
GET /latest
```
Get historical rates for any day since 1999.
```http
GET /2000-01-03
```
Rates are quoted against the Euro by default. Quote against a different currency by setting the base parameter in your request.
```http
GET /latest?base=USD
```
2017-11-04 18:59:51 +01:00
Request specific exchange rates by setting the symbols parameter.
2016-04-11 15:38:28 +02:00
```http
GET /latest?symbols=USD,GBP
```
2017-11-10 10:43:26 +01:00
The primary use case is client side. For instance, with [money.js](https://openexchangerates.github.io/money.js/) in the browser
2016-04-11 15:38:28 +02:00
```js
2017-11-04 18:59:51 +01:00
let demo = () => {
let rate = fx(1).from("GBP").to("USD")
2016-04-11 15:38:28 +02:00
alert("£1 = $" + rate.toFixed(4))
}
2017-11-04 18:59:51 +01:00
fetch('https://api.fixer.io/latest')
.then((resp) => resp.json())
.then((data) => fx.rates = data.rates)
.then(demo)
```
2016-04-11 15:38:28 +02:00
2017-11-04 18:59:51 +01:00
## Installation
2016-04-12 15:57:20 +02:00
2017-11-04 18:59:51 +01:00
To run locally with Docker, type
2016-04-11 15:38:28 +02:00
```bash
docker-compose up -d
2016-04-11 15:38:28 +02:00
```
2017-11-04 18:59:51 +01:00
Then seed data with
2016-04-11 15:38:28 +02:00
```bash
docker-compose run web rake db:migrate rates:load
```
2017-11-10 10:43:26 +01:00
Now you can access the API at
2017-11-04 18:59:51 +01:00
```
http://localhost:8080
```
2017-11-13 00:17:18 +01:00
In production, create a [`.env`](.env.example) file in the project root and run with
2017-11-04 18:59:51 +01:00
```bash
2017-11-13 00:17:18 +01:00
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
2017-11-04 18:59:51 +01:00
```