Expand description
§unirate-axum
Axum integration for the UniRate API — free, real-time currency exchange rates, conversion, and VAT rates.
This crate exposes a ready-made router that mounts four GET routes on
top of the official unirate_api::Client:
| Route | Query params | Backing client call |
|---|---|---|
/rate | from, to | Client::get_rate / Client::get_all_rates |
/convert | from, to, amount | Client::convert |
/currencies | — | Client::get_supported_currencies |
/vat | country (optional) | Client::get_vat_rate / Client::get_vat_rates |
UniRate errors are mapped to the matching HTTP status with a JSON error
body via ApiError.
§Client sourcing
The UniRate HTTP client itself is not re-implemented here — this crate
depends on the published unirate-api
crate (unirate_api::Client) and only adds the Axum wiring. That keeps the
client parity in one place and this crate small.
§Quick start
use unirate_axum::router;
use unirate_api::Client;
#[tokio::main]
async fn main() {
let client = Client::new(std::env::var("UNIRATE_API_KEY").unwrap());
let app = router(client);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}§Composing into a larger app
router returns a plain axum::Router, so you can nest it under a
prefix or merge it into an existing router:
use axum::Router;
use unirate_axum::router;
use unirate_api::Client;
let client = Client::new("your-api-key");
let app: Router = Router::new().nest("/currency", router(client));Structs§
- ApiError
- Wraps a
UniRateErrorand turns it into an HTTP response. - Convert
Params - Query params for
GET /convert. - Convert
Response - Body of a successful
GET /convert. - Currencies
Response - Body of a successful
GET /currencies. - Rate
Params - Query params for
GET /rate. - VatAll
- Body of a successful
GET /vat(all countries). - VatCountry
- Body of a successful
GET /vat?country=XX. - VatParams
- Query params for
GET /vat. - VatRate
Body - VAT rate for a single country, as returned in a JSON response.
Functions§
- router
- Build an
axum::Routerwired to the givenClient.