Simple currency REST API. Parse https://nationalbank.kz/rss/rates_all.xml?switch=kazakh and save to db. History saves when refreshing too
- Go
- PostgreSQL
- Cron
- Item 3a
git clone github.com/gospodinzerkalo/currency_api
docker-compose build
docker-compose up
POSTGRES_HOST: db
POSTGRES_DATABASE: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
You can change cycle of job scheduler, I have put "@every 10s" for testing. For daily refresh pus "@daily"
_, err = cr.AddFunc("@every 10s", func() {
if err := currencyService.RefreshCurrencies(); err != nil {
log.Fatal(err)
}
})
GET http://localhost:8080/currency
response
[
{
"currency_pair": "TRY/KZT",
"value": "57.38"
},
{
"currency_pair": "UZS/KZT",
"value": "4.04"
},
...
]
GET http://localhost:8080/currency?base=USD"ed=RUB
response
[
{
"currency_pair": "USD/RUB",
"value": "75.22"
}
]
POST http://localhost:8080/convert
Request body
{
"convert_from": "USD",
"convert_to": "RUB",
"value" : 1
}
Response
{
"convert_from": "USD",
"convert_to": "RUB",
"convert_from_value": 1,
"convert_to_value": "75.2193"
}
GET http://localhost:8080/history
Response
[
{
"id": 1,
"title": "AUD",
"pub_date": "28.01.2021",
"change": "+1.44"
}, ...
]