Skip to content

Federal Office for Customs and Border Security FOCBS as an API

License

Notifications You must be signed in to change notification settings

rbolog/focbs-rates-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

focbs-rates-api

Federal Office for Customs and Border Security FOCBS Daily rates (exchange rates) as an API

Purpose

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

Project structure

Cron worker

Purpose

Periodically extract data from the federal site, transform it, and store each element in a Cloudflare key/value store.

Project README

API worker

Purpose

API implemention, using Cloudflare worker

Project README

Requests samples

#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:

  1. jq is a lightweight and flexible command-line JSON processor

  2. 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.

General information

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 = ""

Minimum tools

A development environment with

Documentation

Terms and conditions of use of the data

See Terms and conditions of use of the data from offical site: https://www.rates.bazg.admin.ch/home

License

The source code is covered by the "BSD-3-Clause" licence. See the file LICENSE

About

Federal Office for Customs and Border Security FOCBS as an API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published