Expand description
Rust bindings to the Frankfurter API
§Usage
use lib_frankfurter::{
api::{convert, currencies, period, ServerClient},
chrono::NaiveDate,
url::Url,
};
#[tokio::main]
async fn main() {
let server_client: ServerClient = Url::parse("http://localhost:8080")
.map(ServerClient::new)
.unwrap_or_default();
// Fetch supported currencies - this request does not accept any additional options
match server_client
.currencies(currencies::Request::default())
.await
{
Ok(resp) => {
println!("{}", serde_json::to_string_pretty(&resp).unwrap())
}
Err(e) => panic!("{e:?}"),
}
// Fetch latest exchange rates - for available, options check out [`convert::Request`]
match server_client.convert(convert::Request::default()).await {
Ok(resp) => {
println!("{}", serde_json::to_string_pretty(&resp).unwrap())
}
Err(e) => panic!("{e:?}"),
};
// Fetch exchange rates from 01/01/2024 to the present date - for available options, check out [`period::Request`]
match server_client
.period(period::Request {
start_date: NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
..Default::default()
})
.await
{
Ok(resp) => {
println!("{}", serde_json::to_string_pretty(&resp).unwrap());
}
Err(e) => panic!("{e:?}"),
};
}
Re-exports§
pub use chrono;
pub use reqwest;
pub use serde_json;
pub use url;
Modules§
- Interface to the Frankfurter API.
Structs§
- Value of a currency. Simple wrapper around an
f64
.
Enums§
- Possible currency codes (ISO 4217) returned by the
Frankfurter
API. - Possible errors that can be encountered when making requests using the
crate::api::ServerClient
.
Type Aliases§
- A map of
Currency
to their respectiveCurrencyValue
, sorted by the currency code keys.