Federal Office for Customs and Border Security FOCBS Daily rates (exchange rates) as an API
This small project was used to demonstrate the use of Cloudflare workers as part of a quick and easy API implementation. The (real) example provides exchange rate data from the Swiss Federal Customs Office. The data is published as an xml once a day, which we transformed into a REST API
Federal Office for Customs and Border Security FOCBS
Periodically extract data from the federal site, transform it, and store each element in a Cloudflare key/value store.
./cron/README.md
- Github cron root
API implemention, using Cloudflare worker
./api/README.md
- Github api root
#export URL='http://localhost:8787/'
export URL='https://ratesapi.ilab-dgnsi-vd.ch'
curl -s "${URL}/all" | jq
curl -s "${URL}/currency/eur" | jq
curl -s "${URL}/currency/exist/clp" | jq
curl -s "${URL}/rate/?to=usd&amount=100.50" | jq
curl -s "${URL}/rate/?from=usd&to=chf&amount=100" | jq
Notes:
-
jq is a lightweight and flexible command-line JSON processor
-
The
https://ratesapi.ilab-dgnsi-vd.ch
url is currently restricted to Switzerland.a. This service is for demonstration purposes only. There is no guarantee of availability.
The wrangler.toml configuration file is not included; you need to create one for each project. wrangler.toml.sample can be used as the base for each project. The KV base is shared, so you need the same id in both wrangler.toml configuration files.
[[kv_namespaces]]
binding = "KV_CURRENCIES_RATES"
id = ""
#preview_id = ""
A development environment with
See Terms and conditions of use of the data from offical site: https://www.rates.bazg.admin.ch/home
The source code is covered by the "BSD-3-Clause" licence. See the file LICENSE