Skip to content

UniRate-API/cloudflare-workers-unirate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cloudflare-workers-unirate

Cloudflare Worker template that serves currency exchange rates via the UniRate API, built with Hono.

Deploy a lightweight edge proxy that keeps your UniRate API key server-side while exposing clean JSON endpoints to your frontend.

Features

  • Three ready-to-use endpoints: exchange rates, currency conversion, supported currencies
  • API key stays in Cloudflare secrets — never exposed to browsers
  • Input validation and sanitization on all currency codes and amounts
  • Correct HTTP error codes mirrored from UniRate (401, 403, 404, 429, 502)
  • Zero runtime dependencies beyond Hono
  • TypeScript throughout

Quick start

# 1. Clone and install
git clone https://github.com/UniRate-API/cloudflare-workers-unirate
cd cloudflare-workers-unirate
npm install

# 2. Add your UniRate API key as a Wrangler secret
wrangler secret put UNIRATE_API_KEY

# 3. Run locally
npm run dev

# 4. Deploy
npm run deploy

Get a free UniRate API key at unirateapi.com.

Endpoints

All endpoints accept query parameters and return JSON.

GET /rate

Current exchange rate between two currencies.

Param Required Default Description
from no USD Source currency (3-letter ISO code)
to no Target currency. Omit to return all rates for from
# Single pair
curl https://your-worker.workers.dev/rate?from=USD&to=EUR
# → {"rate":"0.92"}

# All rates for USD
curl https://your-worker.workers.dev/rate?from=USD
# → {"rates":{"EUR":"0.92","GBP":"0.79",...}}

GET /convert

Convert an amount between two currencies.

Param Required Default Description
from no USD Source currency
to yes Target currency
amount no 1 Amount to convert (positive number)
curl "https://your-worker.workers.dev/convert?from=USD&to=EUR&amount=100"
# → {"result":"92.50"}

GET /currencies

List all supported currency codes.

curl https://your-worker.workers.dev/currencies
# → {"currencies":["USD","EUR","GBP",...]}

Error responses

Status Meaning
400 Missing or invalid parameter
401 Invalid API key
403 Endpoint requires a Pro subscription
404 Currency not found
429 Rate limit exceeded
502 UniRate upstream error
{"error":"Missing or invalid \"to\" parameter"}

Running tests

npm test

21 mock tests covering all routes, error paths, currency code validation, header behaviour, and API key non-exposure.

Free vs Pro tier

Free tier covers /rate, /convert, and /currencies. Historical endpoints require a Pro subscription and are not included in this template.

Related packages

UniRate API client libraries: Python · Node.js · Go · Rust · Ruby · PHP · Java · Swift · .NET

Framework integrations: Next.js · Nuxt · SvelteKit · Astro · NestJS · Remix · Angular · Vue · React

CMS / e-commerce: Strapi · Directus · Medusa · WordPress · Drupal · Wagtail · Django REST

PHP ecosystem: Laravel Money · Symfony Bundle

Data & AI: LangChain Python · LangChain.js · FastAPI · Flask · dbt · Airflow

Platform: MCP server · CLI · Home Assistant · Cloudflare Workers (this template) · Jekyll · Hugo · Eleventy · Astro

License

MIT © Unirate Team

About

Cloudflare Worker template: serve currency exchange rates via the UniRate API using Hono

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors