unirate-api

Official Haxe client for the UniRate API — free currency exchange rates, historical data, and VAT rates. Zero dependencies (haxe.Http + haxe.Json).
https://unirateapi.com

To install, run:

haxelib install unirate-api 0.1.0 

See using Haxelib in Haxelib documentation for more information.

README.md

UniRate API — Haxe client

Official Haxe client for the UniRate API — free currency exchange rates, historical data, and VAT rates.

  • Zero dependencies. HTTP via haxe.Http, JSON via haxe.Json — both in the Haxe standard library. Nothing else is pulled in.
  • Injectable transport, so your tests never touch the network.
  • Works on the sys targets (eval, HashLink, Neko, C++, …).

Install

haxelib install unirate-api

Then add -lib unirate-api to your build (.hxml).

Quick start

import unirate.UniRateClient;

class Main {
	static function main() {
		var client = new UniRateClient("your-api-key");

		// Current rate
		var rate = client.getRate("USD", "EUR");          // 0.92

		// Convert an amount
		var eur = client.convert(100, "USD", "EUR");      // 92.5

		// All rates for a base currency
		var all = client.getAllRates("USD");              // Map<String, Float>

		// Supported currency codes
		var codes = client.getSupportedCurrencies();      // ["USD", "EUR", ...]
	}
}

Get a free API key at unirateapi.com.

API

Construct a client with your API key (plus optional base URL, timeout in seconds, and a custom Transport):

new UniRateClient(apiKey, ?baseUrl, ?timeout, ?transport);

Current rates & conversion (free tier)

MethodReturns
getRate(from, to)Float — rate from from to to
getAllRates(?from)Map<String, Float> — every rate for a base (default "USD")
convert(amount, from, to)Float — converted amount
getSupportedCurrencies()Array<String> — currency codes

VAT (free tier)

MethodReturns
getVatRates()VatRatesResponse
getVatRate(country)VatCountryResponse (ISO-3166 alpha-2, e.g. "DE")

Historical data (requires a Pro subscription)

These return 403 on the free tier (surfaced as an ApiError with status == 403):

MethodReturns
getHistoricalRate(date, from, to)Float
getHistoricalRates(date, ?base)Map<String, Float>
convertHistorical(amount, from, to, date)Float
getTimeSeries(startDate, endDate, ?base, ?currencies, ?amount)Map<String, Map<String, Float>>
getHistoricalLimits()HistoricalLimitsResponse

Currency and country codes are upper-cased before being sent.

Error handling

All errors extend unirate.UniRateError. Catch the base type for everything, or narrow to a specific case:

import unirate.Errors;

try {
	var rate = client.getRate("USD", "EUR");
} catch (e:AuthenticationError) {
	// 401 — missing or invalid API key
} catch (e:RateLimitError) {
	// 429 — rate limit exceeded
} catch (e:ApiError) {
	// 403 (Pro-gated), 503, or any other non-2xx — inspect e.status / e.body
	trace(e.status);
} catch (e:UniRateError) {
	// InvalidCurrencyError (404), InvalidDateError (400), transport errors, ...
}
StatusError
400InvalidDateError
401AuthenticationError
403ApiError (status 403) — "Endpoint requires a Pro subscription"
404InvalidCurrencyError
429RateLimitError
503ApiError (status 503) — "Service unavailable"
other / networkApiError / UniRateError

Rate limits

The free tier is rate-limited. On 429 the client throws RateLimitError; back off and retry.

Testing

Mock tests use an injected transport and never hit the network:

haxe -cp src -cp test -main TestClient --interp

Live tests (free-tier endpoints only) run when UNIRATE_API_KEY is set:

UNIRATE_API_KEY=... haxe -cp src -cp test -main LiveTest --interp

Related clients

Official UniRate clients exist for Python, Node/TypeScript, Go, Rust, Java, Ruby, PHP, Swift, Elixir, and more. See github.com/UniRate-API.

License

MIT © 2026 Unirate Team. Source: https://github.com/UniRate-API/unirate-api-haxe

Contributors
unirateapi
Version
0.1.0
Published
4 weeks ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂