frankfurter/README.md

92 lines
1.9 KiB
Markdown
Raw Normal View History

2018-04-16 17:19:15 +02:00
# Frankfurter
2018-04-16 17:19:15 +02:00
[![Travis](https://travis-ci.org/hakanensari/frankfurter.svg)](https://travis-ci.org/hakanensari/frankfurter)
2015-07-28 17:27:10 +02:00
2018-09-11 18:59:18 +02:00
Foreign exchange (forex) rates and currency conversion API
## Getting Started
Frankfurter is a free, open source API for current and historical foreign exchange rates. It tracks data published by the European Central Bank.
2016-04-11 15:38:28 +02:00
2017-11-04 18:59:51 +01:00
Rates are updated around 4PM CET every working day.
2018-09-11 18:59:18 +02:00
## Examples
Get the current foreign exchange rates.
2016-04-11 15:38:28 +02:00
```http
2018-09-11 18:59:18 +02:00
GET /latest HTTP/1.1
2016-04-11 15:38:28 +02:00
```
Get historical rates for any day since 1999.
```http
2018-09-11 18:59:18 +02:00
GET /2000-01-03 HTTP/1.1
```
Get historical rates for a time period.
```http
GET /2010-01-01..2010-01-31 HTTP/1.1
2016-04-11 15:38:28 +02:00
```
Rates quote against the Euro by default. Quote against a different currency.
```http
2018-09-11 18:59:18 +02:00
GET /latest?from=USD HTTP/1.1
```
Request specific exchange rates.
2016-04-11 15:38:28 +02:00
```http
2018-09-11 18:59:18 +02:00
GET /latest?to=USD,GBP HTTP/1.1
2016-04-11 15:38:28 +02:00
```
2018-09-11 18:59:18 +02:00
Convert a specific amount.
2016-04-11 15:38:28 +02:00
```http
2018-09-11 18:59:18 +02:00
GET /latest?amount=1000&from=GBP&to=USD HTTP/1.1
2016-04-11 15:38:28 +02:00
```
2018-09-11 18:59:18 +02:00
With a full list of currencies, time series grow large in size. For better performance, use the to parameter to reduce the response weight.
2018-03-17 15:28:52 +01:00
```http
2018-09-11 18:59:18 +02:00
GET /2016-01-01..2016-12-31?from=GBP&to=USD HTTP/1.1
2018-03-17 15:28:52 +01:00
```
2018-09-11 18:59:18 +02:00
Here we return the current GBP/USD currency pair with JavaScript.
2016-04-11 15:38:28 +02:00
```js
2018-09-11 18:59:18 +02:00
// Fetch and display GBP/USD
fetch('/latest?from=GBP&to=USD')
.then(resp => resp.json())
.then((data) => { alert(`GBPUSD = ${data.rates.USD}`); });
```
2016-04-11 15:38:28 +02:00
2018-09-11 18:59:18 +02:00
Cache data whenever possible.
## Deployment
2016-04-12 15:57:20 +02:00
2018-01-08 13:34:02 +01:00
To build locally, type
2016-04-11 15:38:28 +02:00
```bash
docker-compose up -d
2016-04-11 15:38:28 +02:00
```
2018-09-11 19:12:08 +02:00
Now you can access the API at `http://localhost:3000`.
2017-11-04 18:59:51 +01:00
2018-09-11 18:59:18 +02:00
In production, create a [`.env`](.env.example) file 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
```
2018-03-09 13:35:43 +01:00
2018-09-11 18:59:18 +02:00
To update to a newer image, run
2018-03-09 13:35:43 +01:00
```bash
docker-compose -f docker-compose.yml -f docker-compose.prod.yml pull
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
```
2018-09-11 18:59:18 +02:00
Within a few minutes, you will access the API at `https://yourdomain.com`.