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.
- 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
# 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 deployGet a free UniRate API key at unirateapi.com.
All endpoints accept query parameters and return JSON.
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",...}}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"}List all supported currency codes.
curl https://your-worker.workers.dev/currencies
# → {"currencies":["USD","EUR","GBP",...]}| 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"}npm test21 mock tests covering all routes, error paths, currency code validation, header behaviour, and API key non-exposure.
Free tier covers /rate, /convert, and /currencies. Historical endpoints require a Pro subscription and are not included in this template.
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
MIT © Unirate Team