The HolidayAPI client for Rust projects.
📆⚙️ HolidayAPI client wrapper for Rust projects.
| Service | Status |
|---|---|
| crates.io |
Pure Rust bindings to the Holiday API.
holiday_api is intended to work on all tier 1 supported Rust systems:
holiday_api requires rustc 1.75 or higher (edition 2021, async/await).
Add the following to your Cargo.toml:
[dependencies]
holiday_api = "1.0.0"
tokio = { version = "1", features = ["full"] }
Then in your main.rs:
use holiday_api::HolidayAPIClient;
#[tokio::main]
async fn main() {
let client = HolidayAPIClient::new("YOUR_HOLIDAY_API_KEY".to_string());
match client.search_holidays("2019", "BR").await {
Err(e) => eprintln!("{:?}", e),
Ok(Some(holidays)) => {
for holiday in holidays {
println!(
"Holiday: {} | Date: {} | Country: {}",
holiday.name, holiday.date, holiday.country
);
}
}
Ok(None) => println!("No holidays found."),
}
}
All methods are async and must be .awaited.
| Method | Description |
|---|---|
search_holidays(year, country) |
Returns holidays for a given year and country code |
search_countries() |
Returns a list of all supported countries |
search_languages() |
Returns a list of all supported languages |
workday(country, start, days) |
Returns the workday date after N working days from a start date |
workdays(country, start, end) |
Returns the number of working days between two dates |
The API key can be loaded from a .env file using dotenv:
HOLIDAYAPI_APIKEY=your_api_key_here
use dotenv::dotenv;
use std::env;
dotenv().ok();
let api_key = env::var("HOLIDAYAPI_APIKEY").unwrap();
let client = HolidayAPIClient::new(api_key);
Licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).